0% found this document useful (0 votes)
63 views

Database Assignmnet

this database assignment which done in microsoft SQL by Students of Faculty of Management and Computing in Maldives....

Uploaded by

Hucen Azmee
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Database Assignmnet

this database assignment which done in microsoft SQL by Students of Faculty of Management and Computing in Maldives....

Uploaded by

Hucen Azmee
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

1.

Entity Relationship Diagram

Items
Warehouse
PK Item No
PK,FK1 Warehouse ID has / is of PK Warehouse ID

Item Name location


Description
Quantity

Customer_Items

PK,FK1 Item No
has / is of PK,FK1 Warehouse ID
Payment
PK,FK2 Customer ID
PK Payment ID
PK,FK1 Customer ID

Amount
has / is of Date
Payment Type
E-Recipt

PK Recipt ID has / is of
PK,FK1 Customer ID

Item Description

Customer Customer_ Delivery type


has / is of
PK Customer ID PK,FK1 Delivery ID
has / is of PK,FK2 Customer ID
Cart
First Name
PK Cart ID Last Name
PK,FK1 Customer ID has / is of Date of birth
Address
Quantity Phone Number
Mail Address
has / is of

Delivery Person Delivery Type


Package
PK D.person ID PK Delivery ID
PK Package ID has / is of
First Name has / is of PK,FK1 D.person ID Description
Last Name PK,FK2 Delivery ID
Phone no
Mail Address Product Type
No of Items
1.1 Data Dictionary

TABLE NAME key Fields Data type Validation Size Allow Null Deafault
Customer PK Customer ID INT NO
First Name VARCHAR 20 YES
Last Name VARCHAR 20 YES
Phone Number INT YES
Mail Address VARCHAR 30 YES
Address VARCHAR 20 YES
Date Of Birth DATETIME YES

Package PK Package ID INT NO


FK1 D.Person ID INT YES
FK2 Delivery ID INT YES
Product Type VARCHAR 20 YES
No Of Items INT YES

Delivey Type PK Delivery ID INT NO


Description VARCHAR 20 YES

Customer _Delivery type FK1 Delivery ID INT YES


FK2 Customer ID INT YES

Payment PK Payment ID INT NO


FK1 Customer ID INT YES
Amount INT YES
Payment Type VARCHAR 20 YES

Customer_Items FK1 Item No INT YES


FK1 Warehouse Id INT YES
Fk2 Cutomer ID INT YES

E-Recipt PK Recipt ID INT NO


Fk1 Customer ID INT YES
Item Description VARCHAR 30 YES

Items PK Item No INT NO


FK1 Warehouse ID INT YES
Item Name VARCHAR 20 YES
Description VARCHAR 30 YES
Quantity INT YES

Cart PK cart ID INT NO


Customer ID INT YES
Quentity INT YES

Delivery Person PK D.Person ID INT NO


First Name VARCHAR 20 YES
Last Name VARCHAR 20 YES
Phone no INT YES
Mail Address VARCHAR 20 YES
2. The data structure using SQL.

Creating Tables
Cart table

create table Cart


(
CartID int primary key identity,
CustomerID integer,
Quantity integer
)

Customer table

create table Customer


(
CustomerID int primary key identity,
FirstName varchar(20),
LastName varchar(20),
DateOfBirth datetime,
Address varchar(20),
PhoneNumber integer,
MailAdderss varchar(30)
)

Customer_Delivery_Type

create table Customer_delivery_Type


(
DeliveryID int primary key identity,
CustomerID integer
)
Customer_Items Table

create table Customer_items


(
ItemNO int,
CustomerID integer,
WarehousID int
)

Delivery _Type Table

create table Delivery_Type


(
DeliveryID int primary key identity,
Description varchar(20)
)

Delivery Person Table

create table DeliveryPerson


(
D_PersonID int primary key identity,
FirstName varchar(20),
LastName varchar(20),
PhoneNO integer,
MailAddress varchar(30)
)

E- Receipt Table

create table E_Recipt


(
ReciptID int primary key identity,
ItemDescription varchar(30),
CustomerID integer
)
Item Table

create table Items


(
ItemNO int primary key identity,
WarehouseID int,
ItemName varchar(20),
Description varchar(30),
Quintity int
)

Package Table

create table Package


(
PackageID int primary key identity,
ProductType varchar(20),
NoOfItems integer,
D_PersonID integer,
DeliveryID integer
)

Payment Table

create table Payment


(
PaymentID int primary key identity,
CustomerID integer,
Amount int,
Date datetime,
PaymentType varchar(20)
)

Warehouse Table

create table WareHouse


(
WareHouseID int primary key identity,
Location varchar(30)
)
Delivery_Type table

insert into Delivery_Type


values
(
'Air'
)

insert into Delivery_Type


values
(
'Land'
)

insert into Delivery_Type


values
(
'Sea'
)
Item table

insert into Items


values
(
1,'bedroom set','Black color bedroom set',16
)

insert into Items


values
(
2,'sofa set','black color cotton',10
)

insert into Items


values
(
3,'kitchen furnitures','small set for single family',11
)

insert into Items


values
(
4,'chair','computer chair',16
)
Customer_Item table

insert into Customer_items


values
(
5,11,1
)

insert into Customer_items


values
(
6,12,2
)
insert into Customer_items
values
(
7,13,3
)
insert into Customer_items
values
(
8,14,4
)
E Recipt table

insert into E_Recipt


values
(
'computer chair',11
)

insert into E_Recipt


values
(
'small set for single family',12
)

insert into E_Recipt


values
(
'black color cotton',12
)

insert into E_Recipt


values
(
' Black color bedroom set',13
)
WareHouse table

insert into WareHouse


values
(
'male'
)

insert into WareHouse


values
(
'villigili'
)

insert into WareHouse


values
(
'Hulhumale'
)

insert into WareHouse


values
(
'Addu'
)
Package table

insert into Package


values
(
'bedroom set',5,1,2
)

insert into Package


values
(
'Chair',3,3,1
)
insert into Package
values
(
'kitchen furnitures',3,4,2
)
Payment table

insert into Payment


values
(
11,2000,12/2/2008,'Credit Card'
)

insert into Payment


values
(
12,2500,23/11/2008,'Debit Card'
)

insert into Payment


values
(
13,3000,24/1/2008,'Credit Card'
)

insert into Payment


values
(
14,4000,12/12/2010,'Credit Card'
)
Delivery Person table

insert into DeliveryPerson


values
(
'Ibrahim ','Adam',7898738,'[email protected]'
)

insert into DeliveryPerson


values
(
'Shuaib ','Moosa',7456768,'[email protected]'
)

insert into DeliveryPerson


values
(
'Ismail ','Habeeb',7988938, '[email protected]'
)

insert into DeliveryPerson


values
(
'Hassan ','Naushad',7967738,'[email protected]'
)
Cart table

insert into Cart


values
(
11,880
)

insert into cart


values
(
12,700
)

insert into Cart


values
(
13,530
)
insert into Cart
values
(
14,230
)
Customer Delivery Table table

insert into Customer_delivery_Type


values
(
1,11
)

insert into Customer_delivery_Type


values
(
2,12
)

insert into Customer_delivery_Type


values
(
3,13
)

insert into Customer_delivery_Type


values
(
2,14
)
Customer table

insert into customer


values ( 'mohamed', 'irushaad', '17-dec-1983', 'v.aahi', 9921121,
'[email protected]')

insert into customer


values ( 'Hussain', 'Azmee', '09-Apr-1989', 'Violet Villa', 7632209,
'[email protected]')

insert into customer


values ( 'Hussain', 'ihusaan', '27-dec-1983', 'v.aahiy', 9921122,
'[email protected]')

insert into customer


values ( 'mohamed', 'Nazeer', '17-jan-1990', 'hometown', 7655443,
'[email protected]')
3. Selection query

A)

i) Inner Join
Customer table

Cart table

select FirstName + LastName as FullName, Quantity


from customer inner join Cart
on Cart.CustomerID= Customer.CustomerID
ii) Outer Join

Customer table

E_Recipt Table

select FirstName + LastName as FullName, ItemDescription


from customer Left outer join E_Recipt
on E_Recipt.CustomerID= Customer.CustomerID
iii) Selection Query 1

Customer table

select FirstName, LastName, PhoneNumber


from customer
Selection Query 2
Customer table

select* from customer


where FirstName='Hussain'
iv) Projection queries 1
Customer table

select FirstName, LastName, Address


from Customer
where FirstName = 'mohamed'
Projection queries 2

select ItemName, Description, Quintity


from Items
B) Delete Query 1

delete from Payment


where PaymentID = 8

Delete Query 2

delete DeliveryPerson
where FirstName = 'shuaib'

Delete Query 3

delete Payment
where PaymentType = 'Credit Card'
C) Update Query 1

update Items
set Quintity= quintity*2

Update Query 2:

update Customer
set phonenumber=7689673
where LastName= 'Azmee'

Update Query 3:
Update Query 3:

update DeliveryPerson
set MailAddress = '[email protected]'
where LastName = 'Adam'

D) Insert Query 1

insert into Items


values
(
3,'Dressin Table','Brown colour',30
)
Insert Query 2

insert into Payment


values
(
12,3000,1/1/1900,'debit Card'
)

Insert Query 3

insert into E_Recipt


values
(
'Brown Colour',12
)

You might also like