PASCAL

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

UN-NORMALISED TABLE

FIRST NORMAL FORM TABLE

SECOND NORMAL FORM TABLE

THIRD NORMAL FORM TABLE


00139164List of the entities and their respective Attributes

Entities Attributes
Product ProductID, ProductName, ProductType, ProductPrice
Supplier SupplierID, SupplierName, SupplierNum, SupplierAddress
Customer CustomerID, CustomerName, CustomerNum, CustomerAddress
Bill InvoiceNo, Amount, PayType, NumOfItem, ProductID
Order OrderID, OrderDate, OrderTime, ProductID, CustomerID
Store StoreID, StoreLocation, StoreD.Add, ProductID, OrderID
Delivery DeliveryID, DeliveryTime, DeliveryDate, ProductID, SupplierID, InvoiceID, CustomerID

ERD Diagram
C.Data dictionary

 Product

Column Name Data Type Nullability Data Integrity


ProductID Varchar (50) Not Null Primary Key
ProductName Varchar (50) Not Null
ProductType Varchar (50) Not Null
ProductPrice Varchar (50) Not Null

 Supplier

Column Name Data Type Nullability Data Integrity


SupplierID Varchar (50) Not Null Primary Key
SupplierName Varchar (50) Not Null
SupplierNum Varchar (50) Not Null
SupplierAddress Varchar (50) Not Null

 Customer

Column Name Data Type Nullability Data Integrity


CustomerID Varchar (50) Not Null Primary Key
CustomerName Varchar (50) Not Null
CustomerNum Varchar (50) Not Null
CustomerAddress Varchar (50) Not Null

 Bill

Column Name Data Type Nullability Data Integrity


InvoiceNo Integer Not Null Primary Key
Amount Varchar (50) Not Null
PayType Varchar (50) Not Null
NumOfItem Integer Not Null
ProductID Varchar (50) Not Null Foreign Key

 Order

Column Name Data Type Nullability Data Integrity


OrderID Varchar (50) Not Null Primary Key
OrderDate Varchar (50) Not Null
OrderTime Varchar (50) Not Null
ProductID Varchar (50) Not Null Foreign Key
CustomerID Varchar (50) Not Null Foreign Key
 Store

Column Name Data Type Nullability Data Integrity


StoreID Varchar (50) Not Null Primary Key
StoreLocation Varchar (50) Not Null
StoreD.Add Varchar (50) Not Null
ProductID Varchar (50) Not Null Foreign Key
OrderID Varchar (50) Not Null Foreign Key

 Delivery

Column Name Data Type Nullability Data Integrity


DeliveryID Varchar (50) Not Null Primary Key
DeliveryTime Varchar (50) Not Null
DeliveryDate Varchar (50) Not Null
ProductID Varchar (50) Not Null Foreign Key
SupplierID Varchar (50) Not Null Foreign Key
InvoiceNo Integer Not Null Foreign Key
CustomerID Varchar (50) Not Null Foreign Key
TABLE CREATION,

 PRODUCT TABLE CREATION

Create table Product (


ProductID varchar (50) not null constraint pkProductID primary key,
ProductName varchar (50) not null,
ProductType varchar (50) not null,
ProductPrice varchar (50) not null
)

select *from Product


INSERTION OF VALUES

 PRODUCT VALUES
Insert into Product values ('P01','Malt','Staple','75 Ghc')
Insert into Product values ('P02','Fanta','Impulse','15 Ghc')
Insert into Product values ('P03','Coca Cola','Shopping','41 Ghs')
Insert into Product values ('P04','Pepsi','Emergency','67 Ghc')
select *from Product;
Five queries that shows my understanding of SQL

Query 1: order by asc


select *from Supplier
Order by SupplierName asc;

Qwery2:Update
Update Bill
set Amount ='375 Ghs', PayType='Debit card',NumOfItem='5'
where InvoiceNo='1103'
Query 3 delete
delete from Delivery
where DeliveryID='D01' and DeliveryTime='8 Pm'

Query 4 inner join


select Delivery.DeliveryID,Product.ProductID,Delivery.DeliveryDate from Delivery
inner join Product on
Delivery.ProductID=Product.ProductID

Query 5 and
select InvoiceNo,Amount,PayType from Bill where Amount>='150 Ghs' and Amount<='615
Ghs'
Create database retail;

Use retail;

Create table Product(


ProductID varchar(50) not null constraint pkProductID primary key,
ProductName varchar(50) not null,
ProductType varchar(50) not null,
ProductPrice varchar(50) not null
)

Insert into Product values('P01','Malt','Staple','75 Ghc')


Insert into Product values('P02','Fanta','Impulse','15 Ghc')
Insert into Product values('P03','Coca Cola','Shopping','41 Ghs')
Insert into Product values('P04','Pepsi','Emergency','67 Ghc')
select *from Product;
DELETE FROM Product;

Create table Supplier(


SupplierID varchar(50) not null constraint pkSupplierID primary key,
SupplierName varchar(50) not null,
SupplierNum varchar(50) not null,
SupplierAddress varchar(50) not null
)

Insert into Supplier values('K01','Mark','0208810011','Pokuase')


Insert into Supplier values('K02','John','0206610023','Omanjor')
Insert into Supplier values('K03','Luke','0502220044','Rescue')
Insert into Supplier values('K04','Elvis','0275330077','Santa-Maria')

select *from Supplier


Order by SupplierName asc;

create table Customer(


CustomerID varchar(50) not null constraint pkCustomerID primary key,
CustomerName varchar(50) not null,
CustomerNum varchar(50) not null,
CustomerAddress varchar(50) not null
)

Insert into Customer values('C01','Kofi','0276614040','Sowutuom')


Insert into Customer values('C02','Yaw','0505210070','Adenta')
Insert into Customer values('C03','Ama','0206822213','Tema')
Insert into Customer values('C04','Yaa','0277713663','Odorkor')

select *from Customer;

Create table Bill(


InvoiceNo int not null constraint pkInvoiceNo primary key,
ProductID varchar(50) not null constraint fkBillProductID foreign key references
Product(ProductID),
Amount varchar(50) not null,
PayType varchar(50) not null,
NumOfItem int not null
)
select * from Bill;
Insert into Bill values('1101','P02','150 Ghs','Mobile money','10')
Insert into Bill values('1102','P04','1340 Ghs','Debit card','20')
Insert into Bill values('1103','P01','225 Ghs','Credit card','3')
Insert into Bill values('1104','P03','615 Ghs','Cash','15')

select InvoiceNo,Amount,PayType from Bill where Amount>='150 Ghs' and Amount<='615


Ghs'

Update Bill
set Amount ='375 Ghs', PayType='Debit card',NumOfItem='5'
where InvoiceNo='1103'

Create table Ordering (


OrderID varchar(50) not null constraint pkOrderID primary key,
ProductID varchar(50) not null constraint fkOrderingProductID foreign key references
Product(ProductID),
CustomerID varchar(50) not null constraint fkOrderingCustomerID foreign key references
Customer(CustomerID),
OrderDate varchar(50) not null,
OrderTime varchar(50) not null
)

Insert into Ordering values('M01','P02','C03','03/04/2021','6 Am')


Insert into Ordering values('M02','P01','C02','14/07/2022','10 Am')
Insert into Ordering values('M03','P03','C01','06/05/2021','7 Am')
Insert into Ordering values('M04','P04','C04','09/03/2022','8 Am')
select *from Ordering

Create table Store (


StoreID varchar(50) not null constraint pkStoreID primary key,
ProductID varchar(50) not null constraint fkStoreProductId foreign key references
Product(ProductID),
OrderID varchar(50) not null constraint fkStoreOrderID foreign key references
Ordering(OrderID),
StoreLocation varchar(50) not null,
StoreDAdd varchar(50) not null
)
Insert into Store values('S03','P02','M01','Spintex','GA-221-4772')
Insert into Store values('S01','P04','M04','Circle','GA-481-0060')
Insert into Store values('S04','P01','M02','Kumasi','ER-345-2121')
Insert into Store values('S02','P03','M03','Amasaman','TA-672-8631')
select *from Store

Create table Delivery (


DeliveryID varchar(50) not null constraint pkDeliveryID primary key,
ProductID varchar(50) not null constraint fkDeliveryProductID foreign key references
Product(ProductID),
SupplierID varchar(50) not null constraint fkDeliverySupplierID foreign key references
Supplier(SupplierID),
InvoiceNo int not null constraint fkDeliveryInvoiceNo foreign key references
Bill(InvoiceNo),
CustomerID varchar(50) not null constraint fkDeliveryCustomerID foreign key references
Customer(CustomerID),
DeliveryTime varchar(50) not null,
DeliveryDate varchar(50) not null
)

select *from Delivery


Insert into Delivery values('D01','P03','K01','1104','C01','8 Pm','07/05/2021')
Insert into Delivery values('D02','P01','K02','1103','C02','10 Am','15/07/2022')
Insert into Delivery values('D03','P02','K03','1101','C03','11 Pm','04/04/2021')
Insert into Delivery values('D04','P04','K04','1102','C04','6 Am','10/03/2022')
delete from Delivery
where DeliveryID='D01' and DeliveryTime='8 Pm'

--Queries

select Delivery.DeliveryID,Product.ProductID,Delivery.DeliveryDate from Delivery


inner join Product on
Delivery.ProductID=Product.ProductID

You might also like