Quiz 1-Answers

advertisement
IAS2143 Database System
Quiz 1
QUIZ I
Question 1
Use the following Client and Order schema to answer the following questions
Client ( ClientID, Name, Salary, Position)
Order (ProductID, Product, quantity, ,Model, ClientID)
a)
CREATE table client
create table client ( ClientID VARCHAR(10) not null,
Name VARCHAR (40), Salary DECIMAL (7,2), Position VARCHAR(25) )
b)
Find the clients for whom no Position has been specified.
SELECT *
FROM Client
WHERE Position IS NULL
(2 marks)
c)
d)
(2 marks)
Find the clients whom earning more than 50000 per month and list the details in
descending order of Name
SELECT *
FROM Client
WHERE Salary/12 > 50000
ORDER BY Name DESC
(3 marks)
Find the name of clients who have ordered printers.
SELECT distinct C.Name
FROM Client C, Order O
WHERE C.ClietID=O.ClientID
AND O..Product='Printer'
(3 marks)
e)
Find the names of clients who have ordered at least 2 keyboards.
SELECT distinct C.Name
FROM Client C, Order O
WHERE C.ClietID=O.ClientID
AND O.Product='keyboard' AND O.Quantity > =2
(4 marks)
f)
Find the Model of printers ordered by James .
SELECT distinct O.Model
FROM Client C, Order O
WHERE C.Name = ‘James’
and C.ClientID = O. ClientID
g)
What is the average salary of Managers?
SELECT AVG(salary) AS myAvg
FROM EmployeeStatistic
(3 marks)
IAS2143 Database System
Quiz 1
WHERE Position = ‘Manager’
(3 marks)
Question 2
The table shown below lists dentist/patient appointment data. A patient is given an appointment at
a specific time and date with a dentist located at a particular surgery. On each day of patient
appointments, a dentist is allocated to a specific surgery for that day.
staffNo dentistName
patNo patName
Appointment
date time
S1011
Ahmad Bakri
P100
Raju Sivanesan
12Sep09 10am
S15
S1011
Ahmad Bakri
P105
Zira Hijan
12Sep09 12pm
S15
S1024
Mohd Ali
P108
Hafiz Abdul
12Sep09 10am
S10
S1024
Mohd Ali
P108
Hafiz Abdul
14Sep09 2pm
S10
S1032
Roziana Razali
P105
Arif Majid
14Sep09 4pm
S15
S1032
Roziana Razali
P110
Niza Sharif
15Sep09 5pm
S13
a)
surgeryNo
The table shown above is susceptible to update anomalies. Provide examples of insertion,
deletion, and update anomalies.
(6 marks)
Answer:
The student should provide examples of insertion, deletion and update anomalies using the data
shown in the table. Example, a deletion anomaly is if we delete the details of the dentist called
‘Mohd Ali’, we also loose the appointment details of the patient called ‘Hafiz Abdul’. (2 marks)
IAS2143 Database System
Quiz 1
Insertion anomaly is when new dentist is inserted then all other values need to be inserted but it will
be a problem when the dentist not yet assigned to a patient. (2 marks)
Update anomaly is when we update the details of dentist e.g. Ahmad Bakri then all other records
about him need to be updated. (2 marks)
b)
Describe and illustrate the process of normalizing the table from First Normal Form
(1NF) to Third Normal Form (3NF). State any assumptions you make about the data
shown in this table.
(8 marks)
Answer:
The student should state any assumptions made about the data shown in the table. For example, we
may assume that a patient is registered at only one surgery. Also, a patient may have more than one
appointment on a given day.
1NF
Appointment (staffNo, appointmentDate, appointmentTime, dentistName, patNo, patName,
surgeryNo) (1mark)
2NF
Appointment (staffNo, appointmentDate, appointmentTime, patNo, patName) (1mark)
SurgeryReg (staffNo, appointmentDate, surgeryNo) (1mark)
Dentist (staffNo, dentistName) (1mark)
IAS2143 Database System
Quiz 1
3NF
Appointment (staffNo, appointmentDate, appointmentTime, patNo) (1mark)
SurgeryReg (staffNo, appointmentDate, surgeryNo) (1mark)
Dentist (staffNo, dentistName) (1mark)
Patient (patNo, patName) (1mark)
a)
Identify the primary, alternate and foreign keys in your Third Normal Form (3NF) relations.
(6 marks)
Answer:
Appointment - staffNo(PK), appointmentDate(PK), appointmentTime(PK), patNo(FK) – (2 marks
– any one PK and FK)
SurgeryReg - staffNo (PK), appointmentDate(PK), surgeryNo) – (2 marks – 2 PK)
Dentist – staffNo (PK) (1mark)
Patient - patNo (PK) (1mark)
IAS2143 Database System
Quiz 1
Download