Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Column Domain
prod_id Integer (PK)
prod_desc VarChar(200)
cost Float
weight Float
Table: inventory
Column Domain
prod_id Integer (PK)
quantity Integer
location VarChar(10)
Table: orders
Column Domain
order_id Integer(PK)
prod_id Integer(PK)
quantity Integer
Table: order_contents
Column Domain
order_id Integer(PK)
cust_name VarChar(30)
cust_id Integer
cust_address VarChar(100)
4. After your tables have been created. Explain what the appropriate
foreign keys are and why. (You dont have to create them just explain
them)
5. Run the following scrip to insert rows into the product table. (The
deletes to clear the tables have been included in case you need to run
multiple times to fix errors)
delete from exam1.product;
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES
(1,'Baseball',4.99,0.5);
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES
(2,'Basketball',24.99,3);
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES
(3,'Softball',5.99,0.6);
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES (4,'Hockey
Puck',5.99,0.7);
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES (5,'Hockey
stick',99.99,3);
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES (6,'Soccer
Ball',29.99,2);
INSERT INTO exam1.product (prod_id,prod_desc,cost,weight) VALUES (7,'Tennis
Racquet',79.99,3);
6. Using SQL, find the total number of all items in the store. (Save the
SQL statement executed)
7. Write a query that returns the names of all items along with their
quantity including any items out of stock. An out of stock item could be
indicated by a row in the inventory table OR BY NO ROW FOR THAT ITEM IN
THE INVENTORY TABLE (Hint MySQL supports left and right joins)
9. Find the total cost of all items purchased by Donald Trump. (Hint
Arithmetic operations can be performed on columns returned in the select
statement) Rounding is not necessary.
10. Write a SQL query that returns unfillable orders (by order_id) due to
stocking issues (no inventory to fill the order).
12. Explain how a transaction could be used safely insert an order and
update the level of inventory and why one should be used.