Sei sulla pagina 1di 23

1

Database project
Securitas

Submitted To:-

Submitted By:-

Prof.Imran Khan

Nikunjkumar Patel
C0678626

1.

TABLE OF CONTENT

SR

Contents
N

o
1
1.1
1.2
1.3
2
2.1
3
3.1
4
4.1
5
5.1
5.2
5.3

Requirments Analysis
Overview
of
Company
and
Products
Customer
Sales Invoice
Entity &
Attribute
Identification
Conceptual
Design
ER
Diagram
Logical Model
Normalization &
Relational
Schema
Physical
Model
Database
creation
Implementation
of
Physical
Model
Create Database
Tables
Identify Business
Rules/Database Constraints
Constraints
Testing

Pg

No:

Overview of Company
Overview of Company and Services
a. Name: Nikunjkumar Kiritkumar Patel
b. Student Id: C0678626
c. Company Name: Securitas Canada, Ltd
d. Company Type: Service Provider
e. Company Description:
Securitas, a global leader in the security industry, has been providing security services as
well as on-site guarding, remote guarding, mobile guarding, technology solution and investigation
services according to the requirement of the client.
f. Product/ Services
1 Services

Services
Service_code(PK)
Service_name
Service_type
Service_duration
Client_id
Service_charge
Employee_id
Employee_name

Client Sales Invoice


INVOICE

2.

PAYMENT MEMO NO: 456

Securitas Canada, Ltd

DATE: 10 AUGUST 2016

265 York land Boulevard, Suite 500


North York, Ontario M2J 1S5 Country: Canada
Tel: 1-800-268-0545 Mobile: 416-774-2500
info@securitas.ca

To

Bob Joy
Technology Centre
Surrey Research Park
Guildford Surrey GU2 7YG
DURATION

DATE

02/05/2016

DESCRIPTION OF SERVICES

Hiring of On-site guarding services


for construction building

2/05/2015 to
28/4/2016

DAYS /
HOURS
WORKED

RATE PER
DAY /
HOUR
20$

100 per week

2000$

SUBTOTAL

2000.00$

VAT @ 17%

350.00$

TOTAL

2350$

Company registration no: 468654 VAT registration No: 56464


Payment Terms are seven days from receipt of invoice with authorised timesheet
Please make payments to Securitas Canada, Ltd

TOTAL

3 Entities and Attribute identification


Client order service invoice requirements are identified in the previous section with the required tables or
entities and a detailed attribute identified and given below
1.1 Client
Attribute

Data type

Description

Client_ID

Varchar(20)

Primary key

Client name

Varchar(20)

Client full name and not null

Address

Varchar(40)

Client

communication

address
Country

Varchar(20)

Client country

Phone

Long

Client phone number

Service Contract date

Date

Client Contract date

Employee_ID

Varchar(20)

Employee who raised the


Payment Memo

1.2 Payment memo


Attribute

Data type

Description

Memo_Id

Varchar(20)

Payment memo unique id


and primary key

Client_ID

Varchar(20)

Foreign key reference from


the client table

Service_Contract_date

Date

Contract date of the Services

Subtotal

Number

Subtotal of the services

Discount

Varchar(20)

Discounts gives

discount

figure in this table


Branch_ID

Varchar(20)

Branch ID refrence from


discount table

Employee_ID

Varchar(20)

Employee id who raised the


payment memo

1.3 Branch
Attribute

Data type

Description

Branch_ID

Varchar(20)

Branch ID unique id and


primary key

Branch_Location

Varchar(20)

Location of the branch

Branch_Manager

Varchar(20)

Name of the branch manager

Attribute

Data type

Description

Service_ID

Varchar(20)

Unique and primary key

Service name

Varchar(20)

Service name

Hour cost

Number

Service hours cost

Requirement

Varchar(20)

Special

1.4 Services table

discount

or

requirement
Service Category

Varchar(20)

Service category

Discount

Number

Discount

it

gives

the

information of discount

1.5 Employee
Attribute

Data type

Description

Employee_ID

Varchar(20)

Unique and primary key

Employee_name

Varchar(20)

Employee Name

Address

Varchar(20)

Employee Address

Phone

Number

Phone number of employee

1.6 Contract
Attribute

Data type

Description

Contract_ID

Varchar(20)

Unique and primary key

Contract date

Date

Service Contract date

Service_ID

Varchar(20)

Service_ID reference key of


Service table

Client_ID

Varchar(20)

Client_ID reference key of


Client table

Memo_ID

Varchar(20)

Memo_ID reference key of


PaymentMemo table

Contract_Duration

Number

Contract duration is total


duration of contract

ER DIAGRAM

Normalization
First Normal Form (Invoice Table)
Before Normal Form
Memo_ID

Contrac Subtotal
t date

Employee
_id

Client_ID

Branch_Id

Branch_loc
ation

SEC0001

1/05/20
16

$480

E101

CST0001

SCB

scarboroug
h

SEC0001

01/05/2
016

$480

E102

CST0001

BMT

Brampton

SEC0002

02/06/2
016

$120

E102

CST0002

DAT

Downtown

After Normal Form


Memo_ID

Contrac Subtotal
t date

Employee
_id

Client_ID

Branch_Id

Branch_loc
ation

SEC0001

1/05/20
16

$480

E101

CST0001

SCB

scarboroug
h

SEC0001

01/05/2
016

$480

E102

CST0001

BMT

Brampton

SEC0002

02/06/2
016

$120

E102

CST0002

DAT

Downtown

Second Normal Form (Invoice Table)


Before Normal Form

Memo_I
D

Contract
date

Subtotal

Employe
e_id

Client_I
D

Branch_
Id

Branch_l
ocation

SEC0001

1/05/2016

$480

E101

CST000
1

SCB

scarboro
ugh

SEC0002

02/06/2016 $120

E102

BMT

SEC0003

04/06/2016 $120

E103

CST000
2
CST000
2

Brampto
n
Downto
wn

DAT

10

After Normal Form


(1) Invoice Table

Memo_I
D

Contract
date

Subtotal_

Employe
e_id

Client_I
D

SEC0001 1/05/2016 $480

E101

SEC0002 02/06/201 $120


6

E102

CST000
1
CST000
2

(2) Branch

Branch_
Id

Branch_l
ocation

SCB

scarboro
ugh

BMT

Brampto
n

DAT

Downto
wn

Third Normal Form ( All Tables are already in Third Normal Form)

11

Relational Schema
Client(Client_ID, Clientrname, Address, Country, Phone, Employee_ID)
Contract (Contract_ID, Contract_Date, Contract_Duration, Client_ID, Memo_ID, Service_ID)
Employee (Employee_ID, Employeename, Address, Country, Phone)
Paymentmemo (Memo_ID, Service_Contract_Date, Subtotal, Discount, Employee_ID, Branch_ID,
Contract_ID, Client_ID)
Services (Service_ID, Service_Name, Requirement, Service_Category, Discount)
Branch (Branch_ID, Branch_Location, Branch_Manager)

12

Physical and Implementation Model


Physical Model Physical Table Representation
CREATE DATABASE securitas;
USE securitas;
CREATE TABLE client (
Client_ID varchar(255) NOT NULL,
Clientrname varchar(255) NOT NULL,
Address varchar(255) NOT NULL,
Country varchar(255) NOT NULL,
Phone varchar(255) NOT NULL,
Employee_ID varchar(255) NOT NULL,
PRIMARY KEY (Client_ID),
UNIQUE (Client_ID));
CREATE TABLE Paymentmemo(Memo_ID varchar(255) NOT NULL,
Service_Contract_Date varchar(255) NOT NULL,
Subtotal deciomal(10,2) NOT NULL,
Employee_ID varchar(255) NOT NULL,
Branch_ID varchar(255) NOT NULL,
Contract_ID varchar(255) NOT NULL,
Discount decimal(10,2) NOT NULL,
Client_ID varchar(255) NOT NULL);
CREATE TABLE Services
Service_ID varchar(255) NOT NULL
Service_Name varchar(255) NOT NULL,
Requirement varchar(255) NOT NULL
Service_Category varchar(255) NOT NULL
Discount varchar(255) NOT NULL
CREATE TABLE Branch (
Branch_ID varchar(255) NOT NULL,
Branch_Location varchar(255) NOT NULL,
Branch_Manager varchar(255) NOT NULL,
PRIMARY KEY (Branch_ID),
UNIQUE (Branch_ID))
CREATE TABLE Contract (
Contract_ID varchar(255) NOT NULL,
Contract_Date date NOT NULL,
Contract_Duration varchar(255) NOT NULL,
Client_ID varchar(255) NOT NULL,
Memo_ID varchar(255) NOT NULL,
Service_ID varchar(255) NOT NULL,
PRIMARY KEY (Contract_ID),
UNIQUE (Contract_ID))

13

CREATE TABLE Employee (


Employee_ID varchar(255) NOT NULL,
Employeename varchar(255) NOT NULL,
Address varchar(255) NOT NULL,
Country varchar(255) NOT NULL,
Phone varchar(255) NOT NULL,
PRIMARY KEY (Employee_ID),
UNIQUE (Employee_ID))

Insert Command:
INSERT INTO client(Client_ID, Clientrname, Address, Country, Phone, Employee_ID) VALUES
('c101', 'Adam', 'Aligned Assets,Unit 5 River Court, Albert Drive,Woking, Surrey, GU21 5RP', 'UK', '+44
(0) 1483 717 950', 'e101'),
('c102', 'Smith', 'dsfsd', 'UK', '+44 (0) 1483 718 960', 'e102'),
('c103', 'Jones', 'Merrion Way, Leeds LS2 8NZ, United Kingdom\r\n', 'UK', '+44 (0) 1423 888 690', 'e103'),
('c105', 'Wiiliams', 'Market Place, Thorne, Doncaster DN8 5DJ, United Kingdom\r\n', 'UK', '+44 (0) 1423
658 543', 'e104'),
('c106', 'Davies', '11 Market Pl, Normanton WF6 2AU, United Kingdom\r\n', 'UK', '+44 (0) 1423 666 960',
'e105'),
('c107', 'Richardson', 'No1 Leeds, 26 Whitehall Rd E, Leeds LS12 1BE, United Kingdom\r\n', 'UK', '+44
(0) 1469 821 690', 'e106'),
('c108', 'Gray', 'B1222, York YO19 4RN, United Kingdom\r\nWebsite\r\nDirections\r\n', 'UK', '+44 (0)
1435 018 920', 'e107'),
('c109', 'Rose', 'Western House, Western Way, Bradford BD6 2SZ, United Kingdom\r\n', 'UK', '+44 (0)
1439 878 690', 'e108'),
('c110', 'Miller', 'West Bretton, Wakefield WF4 4LG, United Kingdom\r\n', 'UK', '+44 (0) 1432 178 690',
'e109'),
('c104', 'Taylor', 'Dry Sand Foundry, Foundry Square, Leeds LS11 5DL, United Kingdom\r\n', 'UK', '+44
(0) 1460 998 210', 'e110');

INSERT INTO Paymentmemo (Memo_ID, Service_Contract_Date, Subtotal, Discount_ID,


Employee_ID,Branch_ID,Contract_ID) VALUES
('in101', '2016-08-08', '$500', 'd101','e101','b101', 'cn101'),
('in102', '2016-08-10', '$450', 'd102','e102','b102', 'cn102'),
('in103', '2016-08-13', '$30', 'd103','e103','b103', 'cn103'),
('in104', '2016-08-19', '$580', 'd104','e104','b104', 'cn104'),
('in105', '2016-08-21', '$650', 'd105','e105','b105', 'cn105'),
('in106', '2016-08-25', '$400', 'd106','e106','b106', 'cn106'),
('in107', '2016-08-28', '$800', 'd107','e107','b107', 'cn107'),
('in108', '2016-09-03', '$15', 'd108','e108','b108', 'cn108'),
('in109', '2016-09-10', '$320', 'd109','e109','b109', 'cn109'),
('in110', '2016-09-14', '$600', 'd110','e110','b110', 'cn110');

14

INSERT INTO Services ( Service_ID, Service_Name, Requirement, Service_Category, Discount_ID)


VALUES
('s101', 'On-Site Guarding', 'no', 'full time','d101'),
('s102', 'Remote Guarding', 'no', 'part time', 'd101'),
('s103', 'Mobile Guarding', 'no', 'full time', 'd103'),
('s104', 'Security Investigations', 'no', 'full time', 'd104'),
('s105', 'Security Systems and Technology', 'no', 'part time', 'd105'),
('s106', 'On-Site Guarding', 'no', 'part time', 'd106'),
('s107', 'Remote Guarding', 'no', 'full time', 'd107'),
('s108', 'Mobile Guarding', 'no', 'full time', 'd108'),
('s109', 'Security Investigations ', 'no', 'part time', 'd109'),
('s110', 'Security Investigations', 'no', 'full time', 'd110');

INSERT INTO Branch ( Branch_ID , Branch_Location, Branch_Manager) VALUES


('B101', 'scarborough', 'Mr Tarak Darji'),
('B102', 'markham', 'Mr Rajesh Patel'),
('B103', 'north york', 'Mr Hrash Patel'),
('B104', 'etibicoc', 'Mr Neerav Patel'),
('B105', 'Brampton', 'Mr Riyaz Pirani'),
('B106', 'missisaga', 'Mr Nikunj Patel'),
('B107', 'brimly', 'Mr Ramdin Paul'),
('B108', 'elsemere', 'Mr David Gutta'),
('B109', 'Brampton', 'Mr Ron Von Gin'),
('B110', 'markham', 'Mr Sin Su Saa');
INSERT INTO Contract (Contract_ID, Contract_Date , Contract_Duration, Client_ID,Memo_ID
,Service_ID) VALUES
('cn101', '2016-08-08', '3', 'c101','m101','s01'),
('cn102', '2016-08-10', '6', 'c102','m102','s102'),
('cn103', '2016-08-13', '3', 'c103','m103','s103'),
('cn104', '2016-08-19', '6', 'c104','m104','s104'),
('cn105', '2016-08-21', '12', 'c105','m105','s105'),
('cn106', '2016-08-25', '24', 'c106','m106','s106'),
('cn107', '2016-08-28', '12', 'c107','m107','s107'),
('cn108', '2016-09-03', '24', 'c108','m108','s108'),
('cn109', '2016-09-10', '3', 'c109','m109','s109'),
('cn110', '2016-09-14', '6', 'c110','m110','s110');

15

INSERT INTO Employee(Employee_ID, Employeename, Address, Country, Phone) VALUES


('e101', 'Adam', 'Aligned Assets,Unit 5 River Court, Albert Drive,Woking, Surrey, GU21 5RP', 'UK', '+44
(0) 1483 717 950'),
('e102', 'Smith', 'dsfsd', 'UK', '+44 (0) 1483 718 960'),
('e103', 'Jones', 'Merrion Way, Leeds LS2 8NZ, United Kingdom\r\n', 'UK', '+44 (0) 1423 888 690'),
('e105', 'Wiiliams', 'Market Place, Thorne, Doncaster DN8 5DJ, United Kingdom\r\n', 'UK', '+44 (0) 1423
658 543'),
('e106', 'Davies', '11 Market Pl, Normanton WF6 2AU, United Kingdom\r\n', 'UK', '+44 (0) 1423 666
960'),
('e107', 'Richardson', 'No1 Leeds, 26 Whitehall Rd E, Leeds LS12 1BE, United Kingdom\r\n', 'UK', '+44
(0) 1469 821 690'),
('e108', 'Gray', 'B1222, York YO19 4RN, United Kingdom\r\nWebsite\r\nDirections\r\n', 'UK', '+44 (0)
1435 018 920'),
('e109', 'Rose', 'Western House, Western Way, Bradford BD6 2SZ, United Kingdom\r\n', 'UK', '+44 (0)
1439 878 690'),
('e110', 'Miller', 'West Bretton, Wakefield WF4 4LG, United Kingdom\r\n', 'UK', '+44 (0) 1432 178 690'),
('e104', 'Taylor', 'Dry Sand Foundry, Foundry Square, Leeds LS11 5DL, United Kingdom\r\n', 'UK', '+44
(0) 1460 998 210');

16

Identify Business Rules/Database Constraints:


1.Foreign Constraint:For client
ALTER TABLE client
ADD FOREIGN KEY (Employee_ID)
REFERENCES Employee(Employee_ID);
For Contract
ALTER TABLE Contract
ADD FOREIGN KEY (Client_ID)
REFERENCES client(Client_ID);
For
ALTER TABLE Contract
ADD FOREIGN KEY (Service_ID)
REFERENCES Services(Service_ID);
ALTER TABLE Contract
ADD FOREIGN KEY (Memo_ID)
REFERENCES Paymentmemo(Memo_ID);

For Paymentmemo
ALTER TABLE Paymentmemo
ADD FOREIGN KEY (Branch_ID)
REFERENCES Branch(Branch_ID);
ALTER TABLE Paymentmemo
ADD FOREIGN KEY (Employee_ID)
REFERENCES Employee(Employee_ID);
ALTER TABLE Paymentmemo
ADD FOREIGN KEY (Discount_ID)
REFERENCES Discount(Discount_ID);
For Services
ALTER TABLE Services
ADD FOREIGN KEY (Discount_ID)
REFERENCES Discount(Discount_ID);

17

VALID

INVALID

2.Primary Constraint
VALID

INVALID

18

3.UNIQUE CONSTRAINT
INVALID

VALID

19

BUISNESS RULES CONSTRAINTS:-

For Paymentmemo
ALTER TABLE Paymentmemo
ADD CHECK (Subtotal>0);
ALTER TABLE Paymentmemo
ADD CHECK (Discount>20);
ALTER TABLE Paymentmemo
ADD CHECK (Service_Contract_Date>'2016-01-01');
For EMPLOYEE
ALTER TABLE Employee
ADD CHECK (Country = 'canada' or Country='UK');
For BRANCH
ALTER TABLE Branch
ADD CHECK (Branch_Location = 'scarborough' or Branch_Location = 'markham' or Branch_Location =
'north york' or Branch_Location = 'etibicoc' or Branch_Location = 'Brampton' or Branch_Location =
'missisaga' or Branch_Location = 'brimly');

For Contract
ALTER TABLE Contract
ADD CHECK (Contract_Date>'2016-01-01');
ALTER TABLE Contract
ADD CHECK (Contract_Duration >= 3);
For Services
ALTER TABLE Services
ADD CHECK (Service_Category = 'full time' or Service_Category ='part time');

20

VALID

INVALID

2
VALID

INVALID

3
VALID

21

INVALID

4
VALID

INVALID

22

ALL FIELD OF PAYMENT MEMO


View Of Paymentmemo (invoice)
create view securitas as (
select c.client_ID,c.Clientrname, c.Address,c.Phone,c.Country, p.Memo_ID,p.Service_Contract_Date,
P.Discount,s.Requirement,s.Service_Name,s.Service_Category,s.Hour_Cost, cn.Contract_Duration, s.Hour_Cost *
cn.Contract_Duration as TotalSum , (s.Hour_Cost * cn.Contract_Duration - ((s.Hour_Cost * cn.Contract_Duration
)-17.5)) as tax, (( s.Hour_Cost * cn.Contract_Duration )+((s.Hour_Cost * cn.Contract_Duration - ((s.Hour_Cost *
cn.Contract_Duration )-17.5)))) as TotalAmount from
client AS c INNER JOIN Paymentmemo AS p ON c.Client_ID = p.Client_ID
INNER JOIN Services AS s ON s.Client_ID = c.Client_ID
INNER JOIN Contract AS cn ON cn.Contract_ID = p.Contract_ID);

23