1. Using data from the Premiere Products database, define a view named ToplevelCust. It consists of the number, name, address, balance, and credit limit of all customers with credit limits that are greater than or equal to $10,000. Using SOL, create the view definition for ToplevelCust (hint: use CREATE VIEW ToplevelCust AS statement) 2. Write an SOL query to retrieve the number and name of all customers in the ToplevelCust view with balances that exceed their credit limits. 3. Display all the data in the ToplevelCust view. 4. Define a view named PartOrder. lt consists of the part number, description, price, order number, order date, number ordered, and quoted price for all order lines currently on file. Using SOL, write the view definition for PartOrder. (Hint: you need to use three tables: Part, OrderLine, Orders). 5. Display all the data in the PartOrder view. SQL result Host: localhost3306 Database: wagnercs_Premiere Generation Time: Nov 11, 2015 at 02:06 PM Generated by: phpMyAdmin 4.0.10.7 / MySQL 5.6.27 SQL query: SELECT * FROM `PartOrder` LIMIT 0, 30 ; Rows: 30 PartNum Description Price OrderNum NumOrdered QuotedPrice OrderDate AT94 Iron 24.95 21608 11 21.95 2013-10-20 AT94 Iron 24.95 21608 11 21.95 2013-10-20 AT94 Iron 24.95 21608 11 21.95 2013-10-21 AT94 Iron 24.95 21608 11 21.95 2013-10-21 AT94 Iron 24.95 21608 11 21.95 2013-10-23 AT94 Iron 24.95 21608 11 21.95 2013-10-23 AT94 Iron 24.95 21608 11 21.95 2013-10-23 AT94 Iron 24.95 21610 1 495.00 2013-10-20 AT94 Iron 24.95 21610 1 495.00 2013-10-20 AT94 Iron 24.95 21610 1 495.00 2013-10-21 AT94 Iron 24.95 21610 1 495.00 2013-10-21 AT94 Iron 24.95 21610 1 495.00 2013-10-23 AT94 Iron 24.95 21610 1 495.00 2013-10-23 AT94 Iron 24.95 21610 1 495.00 2013-10-23 AT94 Iron 24.95 21610 1 399.99 2013-10-20 AT94 Iron 24.95 21610 1 399.99 2013-10-20 AT94 Iron 24.95 21610 1 399.99 2013-10-21 AT94 Iron 24.95 21610 1 399.99 2013-10-21 AT94 Iron 24.95 21610 1 399.99 2013-10-23 AT94 Iron 24.95 21610 1 399.99 2013-10-23 AT94 Iron 24.95 21610 1 399.99 2013-10-23 AT94 Iron 24.95 21613 4 329.95 2013-10-20 AT94 Iron 24.95 21613 4 329.95 2013-10-20 AT94 Iron 24.95 21613 4 329.95 2013-10-21 AT94 Iron 24.95 21613 4 329.95 2013-10-21 PartNum Description Price OrderNum NumOrdered QuotedPrice OrderDate AT94 Iron 24.95 21613 4 329.95 2013-10-23 AT94 Iron 24.95 21613 4 329.95 2013-10-23 AT94 Iron 24.95 21613 4 329.95 2013-10-23 AT94 Iron 24.95 21614 2 595.00 2013-10-20 AT94 Iron 24.95 21614 2 595.00 2013-10-20 6. Write an SOL query to retrieve the part number, description, order number, and quoted price for all orders in the PartOrder view for parts with quoted prices that exceed $100. SQL result Host: localhost3306 Database: wagnercs_Premiere Generation Time: Nov 11, 2015 at 02:12 PM Generated by: phpMyAdmin 4.0.10.7 / MySQL 5.6.27 SQL query: SELECT PartNum, Description, OrderNum, QuotedPrice FROM PartOrder WHERE QuotedPrice >"100" LIMIT 0, 30 ; Rows: 30 This table does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. PartNum Description OrderNum QuotedPrice AT94 Iron 21610 495.00 AT94 Iron 21610 495.00 PartNum Description OrderNum QuotedPrice AT94 Iron 21610 495.00 AT94 Iron 21610 495.00 AT94 Iron 21610 495.00 AT94 Iron 21610 495.00 AT94 Iron 21610 495.00 AT94 Iron 21610 399.99 AT94 Iron 21610 399.99 AT94 Iron 21610 399.99 AT94 Iron 21610 399.99 AT94 Iron 21610 399.99 AT94 Iron 21610 399.99 AT94 Iron 21610 399.99 AT94 Iron 21613 329.95 AT94 Iron 21613 329.95 AT94 Iron 21613 329.95 AT94 Iron 21613 329.95 AT94 Iron 21613 329.95 AT94 Iron 21613 329.95 AT94 Iron 21613 329.95 AT94 Iron 21614 595.00 AT94 Iron 21614 595.00 AT94 Iron 21614 595.00 AT94 Iron 21614 595.00 AT94 Iron 21614 595.00 AT94 Iron 21614 595.00 AT94 Iron 21614 595.00 AT94 Iron 21617 794.95 AT94 Iron 21617 794.95 7. Create a view named OrdTot. It consists of the order number and order total for each order currently on file. (Hint: the order total is the sum of the number ordered multiplied by the quoted price on each order line for each order, SUM(NumOrdered * QuotedPrice). 8. Display all the data in OrdTot the view: 9. Create an index named Partlndex1 on the PartNum field in the OrderLine table. 10. Create an index named Partlndex2 on the Warehouse field in the Part table. 11. Create an index named Partlndex3 on the Warehouse and Class fields in the Part table. 12. Create an index named Partlndex4 on the Warehouse and On Hand fields in the Part table and list units on hand in descending order. 13. Assume the Part table has been created but there are no integrity constraints. Create the necessary integrity constraint to ensure that the only allowable values for the Class field are AP, HW, and SG. Ensure that the PartNum field is the primary key and that the PartNum field in the OrderLine table is a foreign key that must match the primary key of the Part table. NOTE: After 2 hours of messing with this code, I had no alternative but to do each one individually to get it to do what the problem asks. 14. Add a field named Allocation to the Part table. The allocation is a number representing the number of units of each part that have been allocated to each customer. Set all values of Allocation to zero. Calculate the number of units of part number KV29 currently on order. Change the value of Allocation for part number KV29 to this number. Display all the data in the Part table. This returned the correct calculation, but all other values went to NULL! So I had to run this to get it back to “0”: Final: 15. Increase the length of the Warehouse field in the Part table to two characters. Change the warehouse number for warehouse 1 to 1a. Display all the data in the Part table. 16. What command would delete the Part table from the Premiere Products database? (Do not delete the Part table.) DROP TABLE Part; 17. By analogy of examples in the chapter 4, write a stored procedure that will change the price of a part with a given part number. DELIMITER // CREATE PROCEDURE ChangePrice (PNum CHAR (4), Prc DECIMAL (6,2)) BEGIN UPDATE Part SET Price=Prc WHERE PartNum=PNum ; END // DELIMITER; How would you use this stored procedure to change the price of part AT94 to $26.95? DELIMITER // CREATE PROCEDURE ChangePriceAT94 (PNum CHAR (4), Prc DECIMAL (6,2)) BEGIN UPDATE Part SET Price=Prc WHERE PartNum=PNum ; CASE PartNum WHEN AT94 THEN INSERT INTO Prc VALUES (26.95) END // DELIMITER; NOTE: I tried on this one. I give up. Sorry. 18. By analogy of examples in the Concepts of Database Management - Chap. 4, write the code for the following triggers following the style shown in the text: a. When adding a customer, add the customer's balance times the sales rep's commission rate to the commission for the corresponding sales rep. DELIMITER $$ CREATE TRIGGER new_customer_add AFTER INSERT ON Customer FOR EACH ROW BEGIN UPDATE Rep SET Commission = Commission+(Customer.Balance*Rate) WHERE Customer.Balance=New.Balance ; END$$ DELIMITER ; b. When updating a customer, add the difference between the new balance and the old balance multiplied by the sales rep's commission rate to the commission for the corresponding sales rep. DELIMITER $$ CREATE TRIGGER customer_update AFTER UPDATE ON Customer FOR EACH ROW BEGIN UPDATE Rep SET Commission = Commission + (New.Balance * Rate) - (Old.Balance * Rate) WHERE Customer.Balance=New.Balance ; END$$ DELIMITER ; c. When deleting a customer, subtract the balance multiplied by the sales rep's commission rate from the commission for the corresponding sales rep. DELIMITER $$ CREATE TRIGGER customer_delete AFTER DELETE ON Customer FOR EACH ROW BEGIN UPDATE Rep SET Commission = Commission - (Old.Balance * Rate) WHERE Customer.Balance=Old.Balance ; END$$ DELIMITER ;
© Copyright 2026 Paperzz