Chuck, who recently began working for the Natures Vitamin store, wants to create a database to track his customers purchases. He starts to reflect on how other stores track purchases. He recalls that the hardware store always asks him for his zip code, and the dry cleaners always asks him for his phone number. He also knows that the video rental store gives him a card with a scan bar on the back and a membership number on the front. Last week when he went to the public library and had forgotten his library card, he used his social security number to pull up his record and check out some books. He wants to be able to track customer information (including what products each customer purchases on which days) and also be able to notify them of specials via e-mail or post.
Given the data model below:
Fill in the remaining attributes. For product, include product name and price. For order line, include the number of each product purchased on the specific order. For order, include the date of the order. Decide whether you should include total cost of the order.
Order total can be derived by summing orderlineqty*prodprice.
Write the relational algebra and SQL statement for the following queries:
customer |
SELECT * FROM customer |
customer [custname, custemail] |
SELECT custname, custemail FROM customer |
prodname WHERE price > 10 |
SELECT prodname FROM product WHERE prodprice > 10 |
(product WHERE price > 10) [prodname] |
SELECT prodname FROM product WHERE prodprice > 10 |
(customer WHERE custcity = 'Tampa') INTERSECT (customer WHERE custzip = '33456') |
SELECT * FROM customer WHERE custcity = 'Tampa' AND custzip = '33456' |
customer MINUS ((customer WHERE custzip code = '33456') INTERSECT (customer WHERE custzip code = '33454')) |
SELECT * FROM customer WHERE custzip NOT IN ('33456','33454') |
(customer JOIN order WHERE customer.custid=order.custid) [custfname, custlname, custphone) |
SELECT custfname, custlname, custphone FROM customer, order WHERE customer.custnum = order.custnum |
((orderline[prodid, orderid] DIVIDEBY ORDER[orderid]) JOIN product) [prodid, prodname] |
SELECT prodid, prodname FROM product WHERE NOT EXISTS (SELECT * FROM order WHERE NOT EXISTS (SELECT * FROM orderline WHERE orderline.protid = product.protid AND orderline.ordeidm = order.ordeidm)) |
This page is part of the promotional and support
material for Data Management (open edition) by Richard T. Watson For questions and comments please contact the author |