Docsity

Sales Management Database Design and Analysis, Exercises of Database Programming

Toggle sidebar
bg1
Sale management database has relations as following:
Customer(customerID, customerName, customerPhone, customerAddress)
It stores the information of customers
Staff(staffID, staffName, staffPhone, staffAddress)
It stores the information of staff
Product(productID, productName, Unit, Price)
It stores the information of products
Bill(billID, billDate, customerID, staffID)
It stores the information of bills
BillDetail(billID, productID, quantity)
It stores the information of bill details
Part 1:
Students have to complete all following tasks:
1/ Logic database design: use Draw.io tool to create ERD (Entity relationship
diagram).
pf3
pf4
pf5
pf8

Partial preview of the text

Download Sales Management Database Design and Analysis and more Exercises Database Programming in PDF only on Docsity!

Sale management database has relations as following:

Customer( customerID, customerName, customerPhone, customerAddress)

It stores the information of customers

Staff( staffID, staffName, staffPhone, staffAddress)

It stores the information of staff

Product( productID, productName, Unit, Price)

It stores the information of products

Bill( billID, billDate, customerID, staffID)

It stores the information of bills

BillDetail( billID, productID, quantity)

It stores the information of bill details

Part 1:

Students have to complete all following tasks:

1/ Logic database design: use Draw.io tool to create ERD (Entity relationship

diagram).

2/ Physical database design: Detailed description of each table in the database

Table: Customer

Field name Data type Allow nulls Description

customerID varchar(6) Customer code, primary key

customerName varchar(50) Full name of customer

customerPhone varchar(10) Phone number of customers

customerAddress varchar(50) ^ Address Information of customer

Table: Staff

Field name Data type Allow nulls Description

staffID varchar(6) Staff code, primary key

staffName varchar(50) Full name of staff

staffPhone varchar(10) Phone number of staff

staffAddress varchar(50) ^ Address information of staff

Table: Product

Field name Data type Allow nulls Description

prodcutID varchar(6) Product code, primary key

productName varchar(50) Name of product

Unit varchar(10) Unit of product

Price float Price of product

Table: Bill

Field name Data type Allow nulls Description

billID varchar(6) Bill code, primary key

billDate date Bill date

customerID varchar(6) Customer code, foreign key

staffID varchar(6) Staff code, foreign key

Table: BillDeatail

Field name Data type Allow nulls Description

billID varchar(6) Bill code, foreign key

productID varchar(6) Product code, foreign key

quantity int Quantity of bills

3/ Create Databse called “Sales” and all its tables by SQL

-- create Sales database------ create database Sales

Table Staff

Table Cucstomer

Table Product

Table Bill

Table BillDetail

------Insert data into table: Staff----------- insert into Staff(staffID, staffName, staffPhone, staffAddress) values('01','Hung','11111111','10 Le Duan'); insert into Staff(staffID, staffName, staffPhone, staffAddress) values('02','Lan','22222222','20 Nguyen Thi Minh Khai'); insert into Staff(staffID, staffName, staffPhone, staffAddress) values('03','Ngoc','33333333','100 Le Loi'); insert into Staff(staffID, staffName, staffPhone, staffAddress) values('04','Hoang','44444444','15 Hai Ba Trung'); go ------Insert data into table: Customer----------- insert into Customer(customerID,customerName,customerPhone,customerAddress) values('01', 'Quang Minh', '987654321','3 Le Loi'); insert into Customer(customerID,customerName,customerPhone,customerAddress) values('02', 'Quang Teo', '123456789','1 Le Lai'); insert into Customer(customerID,customerName,customerPhone,customerAddress) values('03', 'Minh Beo', '456789123','3 Nam Ky Khoi Nghia'); go ------Insert data into table: Product----------- insert into Product(productID, productName, Unit, Price) values('LAP01','Laptop Dell','piece', 500 ); insert into Product(productID, productName, Unit, Price) values('LAP02','Laptop Lenovo','piece', 400 ); insert into Product(productID, productName, Unit, Price) values('IP01','Ipad Apple x','piece', 300 ); insert into Product(productID, productName, Unit, Price) values('IP02','Ipad Samsung','piece', 200 ); go ------Insert data into table: Bill----------- insert into Bill(billID, billDate, staffID, customerID) values ('111', '05/04/2020','01','02'); insert into Bill(billID, billDate, staffID, customerID) values ('222', '04/04/2020','01','01'); insert into Bill(billID, billDate, staffID, customerID) values ('333', '03/04/2020','03','01'); go ------Insert data into table: BillDetail----------- insert into BillDetail(billID,productID,quantity) values('111','LAP01', 5 ); insert into BillDetail(billID,productID,quantity) values('111','LAP02', 10 ); insert into BillDetail(billID,productID,quantity) values('111','IP01', 20 ); insert into BillDetail(billID,productID,quantity)

select B.billID, B.billDate, C.customerName,S.staffName, P.productName, P.Price, BD.quantity, P.Price * BD.quantity as Amount from Bill B, Customer C, Staff S, Product P, BillDetail BD where B.billID = BD.billID and B.customerID = C.customerID and B.staffID = S.staffID and BD.productID = P.productID;

3/ List all items with informations as following table and Amount >= 1000:

select B.billID, B.billDate, C.customerName,S.staffName, P.productName, P.Price, BD.quantity, P.Price * BD.quantity as Amount from Bill B, Customer C, Staff S, Product P, BillDetail BD where B.billID = BD.billID and B.customerID = C.customerID and B.staffID = S.staffID and BD.productID = P.productID and P.Price * BD.quantity > = 1000 ;

4/ Statistics by staff as the following table:

-------------------Statatics by staff------------------------ select S.staffID,S.staffName, sum(BD.quantity * P.Price) as Revenue from Staff S, Bill B, BillDetail BD, Product P where S.staffID = B.staffID and B.billID = BD.billID and BD.productID = P.productID group by S.staffID, S.staffName;

5/ Statistics by cuctomers as the following table:

-------------------Statatics by Customer------------------------ select C.customerID, C.customerName, SUM(BD.quantity * P.Price) as Total from Customer C, Bill B, BillDetail BD, Product P where C.customerID = B.customerID

and B.billID = BD.billID and Bd.productID = P.productID group by C.customerID, C.customerName;

6/ Statistics by products as the following table:

-------------------Statatics by Products------------------------ select P.productID,P.productName, Sum (BD.quantity) as Quantity, Sum(BD.quantity * P.Price) as Revenue from BillDetail BD, Product P where Bd.productID = P.productID group by P.productID,P.productName go