CSE101 Homework #7 (15 Points) Joins

Total Page:16

File Type:pdf, Size:1020Kb

CSE101 Homework #7 (15 Points) Joins

Name______Lecture Time ______

CSE101 – Homework #7 (15 points) – Joins

Access Problem: Your snack food company "Junk" has decided to setup a database to keep track of customer orders. Portions of each data table are printed on the sheet at the back of this homework  The database keeps track of each individual store separately (a customer id has been issued for each location). The customer table lists customer id, Store Name (Krogers, Giant Eagle etc), name of a contact and address. So, each Krogers store will have the same store name but a different customer id.  Customer Orders are entered into the system each time a specific store location makes an order. The CustomerID and date are recorded and an automatic OrderID number is assigned into the Orders Table. An order must include a product code and quantity.  The different snack products we sell are listed on the Products table. The table includes the following fields - ProductID, name of the product, selling price $ per carton and a CategoryID . Before answering any of the questions below – please look at the database tables given on the last page of this homework and identify all primary keys and foreign key relationships.

1. (1 Points) What is Referential Data Integrity? Based only on the data shown, has Referential Data Integrity been violated for any of the relationships you identified, and if so which ones?

Referential Data Integrity - is a property that can be set such that records in related tables may not be added if there is no matching record on the table where it is primary.

No referential data integrity has NOT been violated in the database. All Productid’s and CustomerID’s that appear on Orders table are present in Product and Customers table.

2. (2 Points) Assume that you are using the tables Users and Payments below in a query, joining them on the foreign key ID#, to answer the following questions:

Users Payments ID# Name ID# Payment 1 John 2 $10 2 Adam 2 $15 3 Lucy 3 $20

a) (1 point) Briefly explain how the “join” process is performed in Access for the above 2 tables?

Access will first create a master list of all combinations of records from the 2 tables. It then filters out those with unmatched (ID#), leaving only those with matching ID# and ID#.

b) (1/2 point) How many records will the master list contain when combining the above 2 tables? _____9_____

c) (1/2 point) How many records will result in the final dynaset joining these 2 table on the foreign key field ID#.______3_____

Hw7a.doc Page 1 Base questions 3-8 on the database provided at the end of this homework. Assume that only parts of the database tables are shown.

3. (1 points) Write a query to list all products in category PO. Include Product Name, Product ID and Category ID. Sort the results by Product Name in alphabetical order.

Tables Required: Products Join On (Foreign Key)______

Field ProductName Product Category ID ID Table Products Products Products Total Sort Ascending Show x x x Criteria “PO” OR OR

4. (1 Points) A manager from the Kroger head office has requested data from you to help them analyze their purchasing patterns. Using the design view below, write a query to list each Kroger order. The list should include the order id, product id, order date and customer id. The list should be sorted by customer id (ascending) and then by order date -the most current date first.

Tables Required: Orders & Customers Foreign Keys: CustomerID

Field Store Chain Orderid Customerid Product id Order Date Table Customers Orders Orders Orders Orders Total Sort Ascending Descending Show x x x x Criteria “Kroger” OR OR Additional Room for Expressions if needed:

5. (2 Points) A recall was issued on two different product categories that you sell. You will need to contact your customers immediately. Using the design view below, write a query that will list all the orders for items in category PO from before April 15, 2005 or in category PC from after April 15, 2005. The list should include the order id, store chain and contact.

Tables Required: Orders, Customers, Products Foreign Keys: Customerid, Productid

Field Orderid Store Chain Contact Categoryid Order date Table Orders Customers Customers Products Orders

Hw7a.doc Page 2 Total Sort Show x x x Criteria “PO” <#4/15/05# OR “PC” >#4/15/05# OR Additional Room for Expressions if needed:

6. (3 Points) You would like to get a list by order of the total value of that order. The list should include the order id, product id, customer id, quantity and total value of the order (price * quantity). Name this calculation totval.

Tables Required: Orders, Products Foreign Keys : Productid

Field Orderid Productid Customer id Quantity totval: see below Table Orders Products Orders Orders Total Sort Show x x x x x Criteria OR OR Additional Room for Expressions if needed: totval:([orders]![quantity] * [products]![$/carton]

Hw7a.doc Page 3 7. (2 Points) Using the results of query #6, you would like to summarize your orders by product. Create a list by product id that includes the total number of items ordered of that product, and the number of orders for that product.

Tables Required: Query6 Foreign Keys: no join

Field ProductID any field Quantity Table Query6 Query6 Query6 Total Group by Count Sum Sort Show x X x Criteria OR OR Additional Room for Expressions if needed:

8. (3 Points) Using the results of query 6, summarize your orders by store chain. Include the store name, total value of all their orders and the average value of their orders.

Tables Required: Query6, Customers Foreign Keys: Customerid

Field Store Chain Totval Totval Table Customers Query6 Query6 Total Group by Sum Avg Sort Show x x x Criteria OR OR Additional Room for Expressions if needed:

Hw7a.doc Page 4

Products Table Product ID ProductName Category ID $/carton 1 Potato Chips - Sour Cream & Chives PO $7.99 2 Potato Chips - Regular PO $6.89 3 Potato Chips - Lite PO $10.29 4 Potato Chips - Ridged PO $10.19 5 Pretzels - small rings P $6.79 6 Prezels - Large hard P $12.35 7 Pretzels - sticks P $4.55 8 Tortillia chips M $6.50 9 Nacho Chips M $7.70 10 Popcorn - Cheeder Cheese PC $8.29 11 Popcorn - Low Fat PC $12.10 12 Popcorn - Butter PC $7.59

Customers Table Customer ID Store Chain Contact Address City State/Province Zipcode 1 Kroger Kane 110 Broad Street Columbus OH 43229- 99 New Hyde Park 2 Kroger Brodsky Dr Columbus OH 43556- 3 Kroger Haprin Brice Mall Outlet Reynoldsburg OH 43213- 4 Giant Eagle Myers 3 Livingston AV Columbus OH 43209- 5 Giant Eagle Zane 8700 Main Street Columbus OH 43669- 6 SuperDuper Roman 456 James Road Columbus OH 43209-

Orders Table OrderID Customer ID Order Date Shipping Method ProductID quantity 1 6 4/19/05 customer truck 6 1 2 4 4/19/05 customer truck 1 3 3 1 4/21/05 our truck 4 2 4 2 4/22/05 customer truck 11 1 5 4 4/23/05 our truck 1 5

Hw7a.doc Page 5

Recommended publications