Database Reference
In-Depth Information
c. Create a data macro associated with the After Delete event for the Customer table to implement the trigger
in Step 12c. Test the data macro by deleting a customer and ensuring that the corresponding sales rep's
commission is updated correctly.
Henry Books Case
151
Ray Henry would like you to complete the following tasks to help him maintain his database. In the following exer-
cises, you will use the data in the Henry Books database shown in Figures 1-17 through 1-20 in Chapter 1. (If you
use a computer to complete these exercises, use a copy of the original Henry Books database so your data will not
reflect the changes you made in Chapter 3.) If you have access to a DBMS, use the DBMS to perform the tasks and
explain the steps you used in the process. If not, explain how you would use SQL to obtain the desired results.
Check with your instructor if you are uncertain about which approach to take.
1. Create a view named PenguinBooks. It consists of the book code, book title, book type, and book price for
every book published by Penguin USA. Display the data in the view.
2. Create a view named Paperback. It consists of the book code, book title, publisher name, branch number, copy
number, and price for every book copy that is available in paperback. Display the data in the view.
3. Create a view named BookAuthor. It consists of the book code, book title, book type, author number, first name,
last name, and sequence number for each book. Display the data in the view.
4. Create the following indexes. If it is necessary to name the index in your DBMS, use the indicated name.
a. Create an index named BookIndex1 on the PublisherName field in the Publisher table.
b. Create an index named BookIndex2 on the Type field in the Book table.
c. Create an index named BookIndex3 on the BookCode and Type fields in the Book table and list the book
codes in descending order.
5. Drop the BookIndex3 index.
6. Specify the integrity constraint that the price of any book must be less than $90.
7. Ensure that the following are foreign keys (that is, specify referential integrity) within the Henry Books database.
a. PublisherCode is a foreign key in the Book table.
b. BranchNum is a foreign key in the Inventory table.
c. AuthorNum is a foreign key in the Wrote table.
8. Add to the Book table a new character field named Classic that is one character in length.
9. Change the Classic field in the Book table to Y for the topic titled The Grapes of Wrath.
10. Change the length of the Title field in the Book table to 60.
11. What command would you use to delete the Books table from the Henry Books database? (Do not delete the
Book table.)
12. Write a stored procedure that will change the price of a book with a given book code and quality. How would
you use this stored procedure to change the price of any copy of book 1351 whose quality is excellent to
$22.95?
13. Assume the Branch table contains a column called TotalValue that represents the total price for all books at that
branch. Following the style shown in the text, write the code for the following triggers.
a. When inserting a row in the Copy table, add the price to the total value for the appropriate branch.
b. When updating a row in the Copy table, add the difference between the new price and the old price to the
total value for the appropriate branch.
c. When deleting a row from the Copy table, subtract the price on the record being deleted from the total value
for the appropriate branch.
14.
If you are using Access 2010, complete the following steps.
a. Add the TotalValue field to the Branch table. Create and run a query on the Copy table to determine the
appropriate values for this field, and then update the Branch table with these values.
b. Create a data macro associated with the After Insert event for the Copy table to implement the trigger in
Step 13a. Test the data macro by adding a record to the Copy table and ensuring that the corresponding
branch's total value is updated correctly.
Search WWH ::




Custom Search