You are on page 1of 2

Given a relational database named “Beverage management system” including the following tables:

BeverageType (TypeID, TypeName)

Beverage (BevID, BevName, Unit, Quantity, Price, TypeID)

Customer (CusID, CusName, Address, Phone)

Invoice (InvCode, CusID, Date)

InvoiceDetail (InvCode, BevID, Quantity, Price)

Question 1. Use SQL language to execute the following table creation statements:

a. Create BeverageType table with constraints:


- TypeID is primary key
- TypeName is unique
b. Create Beverage table with constraints:
- BevID is primary key
- BevName is unique
- Unit receives one of the values: “bottle”, “can”, “barrel”.
- Quantity (is the number of soft-drinks in stock) and Price are greater than 0.
- TypeID is a foreign key that references to BeverageType table.
c. Create Customer table with constraints:
- CusID is primary key
- Phone can be “NULL”
d. Create Invoice table with constraints:
- InvCode is primary key
- CusID is a foreign key that references to Customer table.
- Date is defaulted to the current date.
e. Create InvoiceDetail table with constraints:
- InvCode and CusID are primary key
- Quantity (is the number of a beverage sold per Invoice) is greater than 0.
f. Implement the following operations on the InvoiceDetail table:
- Add a TotalAmount column with data type “int”.
- InvCode is a foreign key that references to Invoice table.
- BevID is a foreign key that references to Beverage table.
- Price is greater than 1000
g. Remove foreign key constraints that refer to Hoadon tables
h. Add constraint that ensures TotalAmount column of InvoiceDetail table must be greater than 0

Question 2. Use SQL statements to perform the following data manipulations:


a. Add at least 3 rows of data to the tables above. You choose your own data to match the
constraints and datatype on the tables above.
b. Increase the price by 10,000 for items with units of "cans".
c. Delete customers who haven't made a purchase since 2010.
d. Delete Beverage whose quantity is 0.
e. Increase the unit price for the item whose unit is "barrel" by 100,000. However, the unit price
after the increase must not exceed 500,000. If it exceeds 500,000, only take 500,000 only.

Question 3. Use SQL statements to fulfill the following requirements:


a. Show beverage whose units are "cans".
b. List of customers in “HCMC”.
c. Indicate which beverage were sold in the third quarter of 2018.
d. List beverage name and sold quantity of each BevID.
e. List the InvIDs that containing beverage that are both in the category of “Carbonated beverage”
and belongs to the category of "Soft drinks"
f. List Beverage that have never been sold

You might also like