This document contains two parts:
(a) Discusses a relation to record tutorial meetings that is not in 2NF and how to decompose it into 2NF.
(b) Presents two tables in a student database and provides SQL queries:
1) To list students not registered in any modules.
2) To create a view of students averaging better in exams than coursework.
3) To display student details using the view.
(a) A relation in 1NF is used to rec ord meetings between tutors and.docx
1. (a) A relation in 1NF is used to rec ord meetings between tutors
and their tutees: Tutorial Meeting( staffID , staffName, onDate ,
atTime , tuteeID, tuteeName, note) The attributes onDate , a t
Time and note are used to store the date, time and notes for
each tutorial meeting. The primary key is und erlined.
(i) Draw a functional dependency diagram for the relation
Tutorial Meeting . [3 marks]
(ii) Explain why it is not in 2NF. [2 marks]
(iii) Decompose the given relation into relations that are in 2NF
and write the schema for these relations. [2 mark s]
(iv) For each relation in 2NF determine if it is in 3NF and
explain why. [2 marks]
(b) Two tables in a student database are given below: Student(
student ID , name, gender, dob, address, entryYear)
Registration( student ID , mcode , exMark, cwMark) where the
primary keys are underlined and foreign keys are in italic.
(i) Write an SQL statement to list the student IDs and names of
those students who have not yet registered on any modules. [3
marks]
( i i) Write an SQL statement to create a view named betterAtE
xam that list the IDs of those students who on average perform
better in exams than coursework, i.e. a student’s average exam
mark is higher than his/her average coursework mark of all
modules registered by the student. [5 marks]
(i i i) Views may be used to simplify queries. W rite an SQL
statement to display the ID, name and gender of all students
who on average perform better in exams than coursework. You
should make use of the view betterAtExam defined in (ii)
Solution
2. b)
1)Write an SQL statement to list the student IDs and names of
those students who have not yet registered on any modules.
select student_ID,name from Student where student_ID NOT IN
(select student_ID from Registration)
2)Write an SQL statement to create a view named betterAtE
xam that list the IDs of those students who on average perform
better in exams than coursework, i.e. a student’s average exam
mark is higher than his/her average coursework mark of all
modules registered by the student.
create view betterAtExam
select *from Registration avg(exMark)<avg(cwMark) group by
student_ID
(i i i) Views may be used to simplify queries. W rite an SQL
statement to display the ID, name and gender of all students
who on average perform better in exams than coursework.
select student ID , name, gender from betterAtExam
a)Functional dependency
staffID->staffName
tuteeID->tuteeName
staffID,staffName,tuteeID,tuteeName->onDate,atTime,note
B)Primary key(staffID,tuteeID)
All non-key attributes are fully functional dependent on the
primary key(to satsi fy normal form 2nd)
3. but staffname is dependebt of staffId
and tutee name depend on tuteeID
so the above relation is not in 2NF
C)Decomposed relations
staffID,staffName Relation-1
tuteeID,tuteeName Relation-2
taffID,tuteeID,onDate,atTime,note Relation-3