onnect Advanced Database Concepts Final Project Name:-Fatimah Abdullah Al-Jomaie ID:-200800688 Section:-201 Due Date Dec 31, 2012 Individual work Part 1 (Normalization) Answer ALL of the following Questions. (4 marks) 1- A car registration database that keeps information only on currently registered cars uses the following table. There is a globally unique serial number for each car but the license plate number is only unique within each country. A car with a license plate in a certain country must be registered in an office located in that country. Each registration office serves one country. Cars (make, model, year, serialNo, color, licensePlateNo, country, registrationOffice, ownerId) a) Write down a set of functional dependencies that covers all the dependencies in this scenario. Answer FD1: serialNo make, model, year, color, licensePlateNo, country, registrationOffice, ownerId. FD2: licensePlateNo, country serialNo. FD3: registrationOffice country. b) Determine all the candidate keys for the relation Cars (Minimum two keys Answer 1- SerialNo 2- (licensePlateNo, country) c) Select each of the candidate keys identified in turn to be the primary key. In each case, and based on each primary key, what is the highest normal form to which the relation Cars conforms? Explain your answer in Answer serialNo as the primary key, the relation Cars is in the 2NF(Second Normal Form) because its primary key is simple, and all relations with simple non-composite primary keys are in 2NF. But the relation Cars is not in 3NF (Third normal form) because a nonprimary attribute is transitively dependent on the primary key. That means serialNo registrationOffice and registrationOffice country, and nonprimary attribute (country) is transitively dependent on the primary key (serialNo). (licensePlateNo, country) as the primary key, the relation Cars is in 3NF because licensePlateNo or country is a determinant of any other attribute. That means every non-primary attribute is fully functionally dependent on the primary key. This condition makes the relation in the 2NF. And (licensePlateNo, country) registrationOffice and registrationOffice — Country, it means no nonprimary key attribute is transitively dependent on the primary key. It means the relation Cars is in 3NF. d) Normalize the relation Cars to the next higher normal form. Indicate to which normal form(s) the resulting relations now conform? And why? Answer The first relation cars is in the 2NF to do it in 3NF it should be no nonprimary key attribute is transitively dependent on the primary key. serialNo registrationOffice and registrationOffice country, and this has a transitive dependent it means that a nonprimary attribute (country) is transitively dependent on the primary key (serialNo), then, the relation Cars is not in 3NF. To do it in 3NF it should create another list to remove any transitive dependence Like this Cars (make, model, year, serialNo, color, licensePlateNo, country, ownerId) RegistrationOffices (registrationOffice, country) The second relation cars are already in the Third normal form also it can do it like this Cars (make, model, year, serialNo, color, licensePlateNo, country, ownerId) RegistrationOffices (registrationOffice, country) Part 2 (SQL Statements) Answer ALL of the following Questions. (6 marks) The Hospital relational headings Team (TeamCode, TelephoneNo, StaffNo) ConsistsOf (StaffNo, TeamCode) Doctor (StaffNo, DoctorName, Position) Specialist (StaffNo, Specialism) Patient (PatientId, PatientName, Gender, Height, Weight, StaffNo, WardNo) Ward (WardNo, WardName, NumberOfBeds) Nurse (StaffNo, NurseName, WardNo) Supervises (StaffNo, Supervisor) Treatment (StaffNo, PatientID, StartDate, Reason) Prescription (PrescriptionNo, Quantity, DailyDosage, StaffNo, PatientId, StartDate, DrugCode) Drug (DrugCode, DrugName, Type, Price) Use the above ERD to answer the following questions: a- Give a list of all drug types without repetition in alphabetical order Answer Select distinct type from drug order by type ASC b- For each Nurse, give a list of his/her StaffNo and the name of his/her supervisor Answer Select s.staff_no,n.nurse_name from nurse u, supervises s, nurse n where u.staff_no = s.staff_no and s.supervisor = n.staff_no c- List the names of doctors who are not specialist Answer select doctor_name from doctor where not exists( select staff_no from Specialist where Specialist.staff_no= doctor.staff_no) Part 3 (PLSQL) Answer ALL of the following Questions. (10 marks) A University has two types of Employees, full time and part-time. Full-time employees receive a monthly salary whereas part-time employees have an hourly rate. Initially, the two types were mutually exclusive, meaning that no employee can be both full-time and part-time at the same time. The company used the following tables: Full-Time-Employee (EmpId, Name, Address, Salary) Part-Time-Employee (EmpId, Name, Address, HourlyRate) Later it was decided to allow full-time employees to work on a part time basis in their spare time and so can be both full-time and part-time employees. To reduce redundancy, the company decided to change the database schema to the following: Employee (EmpId, Name, Address) FT (EmpId, Salary) PT (EmpId, Hourly-Rate) Using cursors create a SQL procedure to convert the old schema into the new one. In order to maintain old application programs, your procedure should also create two views, called Full-Time-Employee and Part-Time-Employee with identical structure of the old tables with the same names. Answer create table full_time_employee ( emp_id int not null, emp_name varchar(25), address varchar(25), salary int, primary key (emp_id) ) insert into full_time_employee(emp_id, emp_name, address, salary) values (123,'Ahamed','Qatif', 500) insert into full_time_employee(emp_id, emp_name, address, salary) values (456,'Ali', 'Dammam', 800) insert into full_time_employee(emp_id, emp_name, address, salary) values (789, 'Mohammed','Jaddah', 600) create table part_time_employee ( emp_id int Not null, emp_name varchar(25), address varchar(25), hourlyRate int, primary key (emp_id) ) insert into part_time_employee (emp_id, emp_name, address, hourlyRate) values (234, 'Malik', 'Riyadh', 12) insert into part_time_employee (emp_id, emp_name, address, hourlyRate) values (567, 'Abdullah', 'Dammam', 15) insert into part_time_employee (emp_id, emp_name, address, hourlyRate) values (891, 'Jone', 'Qatif', 18) create table Employee ( emp_id int not null, emp_name varchar(25), address varchar(25), primary key (emp_id) ) create table FT ( emp_id int not null, salary int, primary key (emp_id) ) create table PT ( emp_id int not null, hourlyRate int, primary key (emp_id) ) CREATE OR REPLACE PROCEDURE emp_fp AS CURSOR f_t_emp_cur IS SELECT ep_no, ep_name, ep_address, ep_sale from full_time_employee; ep_no f_t_emp.ep_no%type; ep_name f_t_emp.ep_name%type; ep_address f_t_emp.ep_address%type; ep_sale f_t_emp.ep_sale%type; CURSOR p_t_emp_cur IS SELECT ep_no, ep_name, ep_address, ep_hR from part_time_employee; ep_no p_t_emp.ep_no%type; ep_name p_t_emp.ep_name%type; ep_address p_t_emp.ep_address%type; ep_hR p_t_emp.ep_hR%type; BEGIN OPEN f_t_emp_cur; OPEN p_t_emp_cur; FETCH f_t_emp_cur INTO ep_no, ep_name, ep_address, ep_sale; FETCH p_t_emp_cur INTO ep_no, ep_name, ep_address, ep_hR; WHILE f_t_emp_cur %found LOOP insert into Employee (emp_id, emp_name, address) values(ep_no, ep_name ,ep_address); insert into FT (emp_id, salary) values (ep_no, ep_name, ep_address, ep_sale); WHILE p_t_emp_cur %found LOOP insert into Employee (emp_id, emp_name, address) values(ep_no, ep_name ,ep_address); insert into PT (emp_id, hourlyRate) values (ep_no, ep_name, ep_address, ep_hR); FETCH f_t_emp_cur INTO ep_no, ep_name, ep_address, ep_sale; FETCH p_t_emp_cur INTO ep_no, ep_name, ep_address, ep_hR; END LOOP; CLOSE f_t_emp_cur ; CLOSE p_t_emp_cur ; END;
© Copyright 2026 Paperzz