Professional Documents
Culture Documents
-2-
CONTENTS
Relational Schemas
Un-Normalized Form ……………………………………………………………………………………… [09]
1st Normalized Form ……………………………………………………………………………………… [10]
2nd Normalized Form ……………………………………………………………………………………… [11]
3rd Normalized Form ……………………………………………………………………………………… [12]
1. Cars
2. Sub-contractors
3. Customers
4. Revenues
5. Expenditures
1. Cars
2. Sub-contractors
a. Credit Allowed sub-contractors
b. Regular sub-contractors
3. Customers
a. Casual customers
b. Privileged customers
4. Expenditures
a. Immediate expenditures
b. Credit liability expenditures
5. Revenues
1. Car: The car entity will hold the information that are
relevant to a car or a vehicle owned by this company.
These vehicles are rented to the customers on a payment
basis. Though the entity is taken as car due to the fact
that most of the vehicles rented are cars, it is possible
that there may be other kind of vehicles like vans in the
table. Registration number of the car, fuel type of the
car, the number of passengers that can travel
simultaneously in the car, insurance information, model
of the car, date of purchase, size of the engine, make of
the car, price at which the car was purchased, the year
-5-
the car was produced and price at which the car is rented
must be the content of this entity.
Relational Schemas
-10-
-11-
-12-
-13-
Un-Normalized Form:
• ContractorServices [PK:requestID,
serviceID(FK:Services.serviceID),
conID(FK:SubContractor.conID), serviceCost]
Normalization Process of
Relational Databases
Not all tables can suffer from these side-effects; rather, the
side-effects can only arise in tables that have not been
sufficiently normalized. An insufficiently normalized table
might have one or more of the following characteristics:
Database Implementation in
MySQL using SQL
/*=========================================================*
* daily operations. *
*CONTACT : sandeep.ellawala@gmail.com *
* +94(0)774055644 *
*=========================================================*/
USE hnd32;
-21-
/*---------------------------------------------------------*
*---------------------------------------------------------*/
make CHAR(20),
fuelType CHAR(7),
passengerCtr TINYINT(2),
engineSize TINYINT(3),
(model > 0)
);
issueDate DATE,
expireDate DATE,
note TINYTEXT,
);
-22-
purchaseDate DATE,
producedYear SMALLINT(4),
carStat CHAR(9),
ON DELETE CASCADE
ON UPDATE CASCADE,
ON DELETE CASCADE
ON UPDATE CASCADE,
);
-23-
conName CHAR(30),
conAddress TINYTEXT,
(conID > 0)
);
serviceName CHAR(40),
serviceDesc TINYTEXT,
(serviceID > 0)
);
ON DELETE CASCADE
ON UPDATE CASCADE,
ON DELETE CASCADE
ON UPDATE CASCADE,
(requestID > 0)
);
description TINYTEXT,
dateSpent DATE,
ON DELETE CASCADE
ON UPDATE CASCADE,
(dateSpent = CURDATE())
);
description TINYTEXT,
dateSpent DATE,
duration TINYINT(2),
ON DELETE CASCADE
ON UPDATE CASCADE,
(duration >= 7)
);
firstName CHAR(20),
lastName CHAR(20),
address TINYTEXT,
TP CHAR(10),
cusStat CHAR(12),
(custID > 0)
);
-26-
ON DELETE CASCADE
ON UPDATE CASCADE,
(licenseNo > 0)
);
incomeDate DATE,
ON DELETE CASCADE
ON UPDATE CASCADE,
(incomeDate = CURDATE())
);
-27-
incomeDate DATE,
duration TINYINT(2),
ON DELETE CASCADE
ON UPDATE CASCADE,
(duration >= 7)
);
rentDate DATE,
duration TINYINT(2),
ON DELETE CASCADE
ON UPDATE CASCADE,
-28-
ON DELETE CASCADE
ON UPDATE CASCADE,
);
resDate DATE,
duration TINYINT(2),
ON DELETE CASCADE
ON UPDATE CASCADE,
ON DELETE CASCADE
ON UPDATE CASCADE,
);
serviceDate DATE,
ON DELETE CASCADE
ON UPDATE CASCADE,
ON DELETE CASCADE
ON UPDATE CASCADE,
(serviceDate = CURDATE())
);
-30-
/*---------------------------------------------------------*
*---------------------------------------------------------*/
DELIMITER //
BEGIN
END IF;
END//
BEGIN
END IF;
END IF;
-31-
END IF;
END//
BEGIN
END IF;
END IF;
END IF;
END//
BEGIN
-32-
END IF;
END//
BEGIN
END IF;
END//
BEGIN
END IF;
END//
BEGIN
END IF;
END IF;
END//
BEGIN
END IF;
END IF;
END IF;
SELECT sub_contractor.creditLimit
INTO conlim
-34-
FROM sub_contractor
END IF;
END IF;
END//
BEGIN
END IF;
END//
BEGIN
END IF;
END//
BEGIN
END IF;
END IF;
END//
BEGIN
END IF;
END IF;
END IF;
SELECT customers.cusStat
INTO cstat
FROM customers
END IF;
END//
BEGIN
END IF;
END IF;
END IF;
END IF;
SELECT customers.cusStat
INTO cstat
FROM customers
END IF;
END//
BEGIN
END IF;
END IF;
END IF;
END IF;
SELECT customers.cusStat
INTO cstat
FROM customers
END IF;
END//
BEGIN
END IF;
END IF;
END//
DELIMITER ;
/*---------------------------------------------------------*
*---------------------------------------------------------*/
/*---------------------------------------------------------*
*---------------------------------------------------------*/
/*---------------------------------------------------------*
*---------------------------------------------------------*/
1,
'nissan',
'diesel',
4,
120
);
1,
"2009.1.10",
"2012.1.9",
''
);
1,
"2009.4.26",
1000000,
"2008",
10000,
1,
1,
''
);
1,
"DMC",
"666, Maharagama.",
);
1,
"paint job",
);
1,
1,
1,
30000
-44-
);
1,
30000,
"spare service",
"2009.4.27",
);
1,
10000,
"",
"2009.4.27",
14,
);
2,
"Rajiv",
"Weerasinghe",
"12, Galle",
"0714054646",
"unprivileged"
);
-45-
2,
);
1,
10000,
"2009.4.27",
);
1,
10000,
"2009.4.27",
10,
);
1,
"2009.4.27",
2,
1,
);
-46-
1,
"2009.4.27",
4,
1,
);
1,
"2009.4.27",
1,
);
/*---------------------------------------------------------*
*---------------------------------------------------------*/
SELECT car.*
car_model.fuelType = "diesel";
SELECT car.*
car_model.fuelType = "petrol";
SELECT *
FROM car
SELECT sub_contractor.*
sub_contractor.conID = contractor_services.conID;
SELECT car.*
car_model.passengerCtr = 4;
SELECT car.*
car_model.passengerCtr > 4;
SELECT *
FROM car
WHERE car.purchasePrice = (
SELECT MAX(purchasePrice)
FROM car
);
-48-
/*---------------------------------------------------------*
* MISC QUERIES *
*---------------------------------------------------------*/
SHOW TRIGGERS;
SHOW TABLES;
-49-
Database Testing
The following sections contain data sets for SQL queries that
can be used to verify the solidness of triggers used in the
database I created for this assignment.
-58-
This MySQL was a free SQL server widely used in the real
world applications with a lot of other free software
components like the Apache web server. There are some minor
and major differences between these two software platforms,
when it comes to the SQL syntax being used. Still using the
reference manual provided online with MySQL, I managed to
understand the syntax and create a working solution.