Chapter 13 Exercises Solution.ZIP

Chapter 13 Exercises Solution

Each of the scripts that you create in the following exercises should use the same general structure as the script presented in figure 13-1 in the book. (screenshot of the script and output)
 

1.)    Write a script that creates and calls a stored procedure named test. This stored procedure should declare a variable and set it to the count of all products in the Products table. If the count is greater than or equal to 7, the stored procedure should display a message that says, “The number of products is greater than or equal to 7”. Otherwise, it should say, “The number of products is less than 7”.

2.)    Write a script that creates and calls a stored procedure named test. This stored procedure should use two variables to store (1) the count of all of the products in the Products table and (2) the average list price for those products. If the product count is greater than or equal to 7, the stored procedure should display a result set that displays the values of both variables. Otherwise, the procedure should display a result set that displays a message that says, “The number of products is less than 7”.

3.)    Write a script that creates and calls a stored procedure named test. This procedure should calculate the common factors between 10 and 20. To find a common factor, you can use the modulo operator (%) to check whether a number can be evenly divided into both numbers. Then, this procedure should display a string that displays the common factors like this: Common factors of 10 and 20: 1 2 5 10
 

4.)    Write a script that creates and calls a stored procedure named test. This procedure should attempt to insert a new category named “Guitars” into the Categories table. If the insert is successful, the procedure should display this message:
 

1 row was inserted.

 If the update is unsuccessful, the procedure should display this message:

 Row was not inserted - duplicate entry.
Powered by