Week 14 Revision
Week 14 Revision
KT24503 Database
Important Dates
01
Revision
ER Diagram to Relational Model Conversion
CarPlate FoodReadyTime
DeliveryNo
Name PickUpAddress
1 M
RIDER Makes DELIVERY
RiderNo
DeliveryAddress
Relational Schema
RIDER (RiderNo, Name, CarPlate)
DELIVERY (DeliveryNo, PickUpAddress, DeliveryAddress, RiderNo, FoodReadyTime)
Foreign Key
6. M:N (many to many) Relationship:
7. 1:1 (one to one) Relationship:
5 .Weak Entity
Relational Schema
Officer (Loan_number, Amount)
Payment (Loan_number, Payment_number, Date)
STEP 1: Write the
relational schema
for all the entities
Employee (EmployeeID, FN, LN, DOB, Company_Name, DateOfJoin, SalaryID, ProjectID, StartDate)
EmployeeContactNo ( EmployeeID, ContactNo)
Project (ProjectID, ProjectName)
Company (CompanyName, Location)
Salary (SalaryID, ModeOfPayment, DateOfSalary)
02
SQL
ERD for HR System
Q1 Answer:
SELECT CONCAT(first_name,last_name)
AS Fullname,salary,department_id
Write a query in SQL to display the FROM employees
full name (first and last name), WHERE manager_id IS NULL
salary, and department number
for those employees who is not
working under a manager.
Q4 Answer:
SELECT d.department_name,
Write a query in SQL to display l.city,
l.state_province
the department name, city, FROM departments d
and state province for each JOIN locations l
ON d.location_id = l.location_id;
department.
Q14 Answer:
SELECT d.department_name,
Write a query in SQL to display COUNT(e.employee_id) AS
the department name and num_employees
FROM departments d
number of employees in each
JOIN employees e
of the department. ON d.department_id =
e.department_id
GROUP BY d.department_name;
03
Normalization
Steps in normalization
34
Need to know the steps:
1. Identify Candidate Keys??
(staffNo, patNo, appointment) staffNo dentistName patNo patName appointment surgeryRoomNo
PATIENT (patNo, patName) S1032 Meliana Santi P110 Scarlett Tan 16-Jan-17 18.00 S13
○ Full dependencies
APPOINTMENT (staffNo, patNo, appointment, surgeryRoomNo)
Step 2: 1NF
Customer (CustNo, CustName, CustAddress, City,
Country)- > partial dependencies
Product (ProductNo, Description, UnitPrice) - > partial
dependencies
2NF/3NF – remove transitive dependencies
Order ( OrderNo, CustNo, ProductNo ,Date, Quantity)
Customer (CustNo, CustName, CustAddress,Country)- full dependencies
Country ( countryId, countryName, cityID)
City (cityID, cityName)
Product (ProductNo, Description, UnitPrice)
Order ( OrderNo, CustNo, ProductNo ,Date, Quantity)
- full dependencies