Вы находитесь на странице: 1из 4

Question 1

a) Analyze the following relational schema and write the SQL code for the given questions.
STUDENT(SID, S_Name, Year)
LECTURER(L_Name, OfficeNumber)
COURSE(CourseID, CourseName, L_Name)
COURSEWORK(SID, CourseID, Marks)

i) What is Hamid office number?


ii) Assume that lecturer Hamid changes his name to Daud. Show the SQL statements
to make the appropriate changes.
iii) What are the names of students who got 75 marks and above for any courses?
iv) Find the names of all current students taking course IAS2143.
v) Find the names of the lecturers who teach each course.
vi) Remove data for student’s name Nabila where her student ID is 200.
(20 marks)

Answer:

i) SELECT OfficeNumber
FROM LECTURER
WHERE L_Name = ‘Hamid’
(3 marks)

ii) UPDATE LECTURER


SET L_Name = ‘Daud’
WHERE L_Name = ‘Hamid’
(3 marks)

iii) SELECT STUDENT.S_Name


FROM STUDENT, COURSEWORK
WHERE STUDENT.SID = COURSEWORK.SID
AND COURSEWORK.Marks >= 75
(4 marks)

iv) SELECT STUDENT.S_Name


FROM STUDENT, COURSEWORK
WHERE STUDENT. SID = COURSEWORK.SID
AND COURSEWORK.CourseID = ‘IAS2143’
(4 marks)

v) SELECT COURSE.Lecturer
FROM COURSE, COURSEWORK, STUDENT
WHERE COURSE.CourseID = COURSEWORK.CourseID
AND COURSEWORK.SID = STUDENT.SID
(4 marks)

vi) DELETE STUDENT


WHERE S_Name = ‘Nabila’ and SID = ‘200’
(2 marks)

Question 2

a) The Gill Art Gallery wishes to maintain data on their customers, artists and paintings.
They may have several paintings by each artist in the gallery at one time. Paintings may
be bought and sold several times. In other words, the gallery may sell a painting, then buy
it back at a later date and sell it to another customer.

Gallery Customer History Form

Customer Name

Miss Fatimah Yusof Phone (013) 323 6000


21 Jalan Meranti Satu
Taman Sri Muda
40400 Shah Alam
Selangor

Purchases Made

Artist Title Purchase Date Sales Price

03 - Carol Channing Laugh with Teeth 09/17/2000 7000.00


15 - Dennis Frings South toward Emerald Sea 05/11/2000 1800.00
03 - Carol Channing At the Movies 02/14/2002 5550.00
15 - Dennis Frings South toward Emerald Sea 07/15/2003 2200.00
Based on the above relation structure, create a new relation structure using record layout in:
i) Create un-normalize form of relational schema
ii) First Normal Form (1NF)
iii) Second Normal Form (2NF)
iv) Third Normal Form (3NF)
(10 Marks)
Answer

i) Un-normalize form

customer [ custno, cust_name, cust_addr, cust_phone, ( artist_id, artist_name, art_title,


pur_date, price) ]
( 1 mark)
ii) First Normal Form (1NF)

customer [ custno, cust_name, cust_addr, cust_phone]


cust_art [ custno, art_code, pur_date, artist_id, artist_name, art_title, price ]

note: the key chosen for the repeating group is the piece of art itself (a code was
assigned), however because a piece of art may be bought by a customer more than once,
the purchase date was added as part of the key to make the rows unique.
(1m x 2 = 2 marks)
iii) Second Normal Form (2NF)

customer [ custno, cust_name, cust_addr, cust_phone]


cust_art [ custno, art_code, pur_date, price ]
art [ art_code, art_title, artist_id, artist_name ]
(1m x 3 = 3marks)

v) Third Normal Form (3NF)

customer [ custno, cust_name, cust_street, cust_city, cust_prov, cust_pstlcd, cust_phone]


cust_art [ custno, art_code, pur_date, price ]
art [ art_code, art_title, artist_id(FK) ]
artist [ artist_id, artist_name ]

(1m x 4 = 4 marks)
b) Draw an entity-relationship model for the following statement:

A university consists of several faculties. Within each faculty there are several
departments. Each department may run a number of programme. Every programme is
composed of several subjects. A lecturer may teach many subjects and each subject may
be taught by a number of lecturers. All subjects is enrolled by many student.
(10 marks)

Answer:

UNIVERSITY consists FACULTY


1 M
1

has
M

PROGRAMME run DEPARTMENT


M 1
1
compose
M

SUBJECT teaches LECTURER


M N

enroll

N
STUDENT

(Each entity 1 mark x 7 = 7 marks, each r/ship ½ m x 6 = 3 marks; total 10 marks)

Вам также может понравиться