Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

Question Two:

Consider a table that stores information about customers and their orders, with the following
:columns

CustomerID (primary key)

CustomerName

CustomerAddress

CustomerCity

CustomerState

OrderID (primary key)

OrderDate

OrderTotal

OrderItem

OrderQuantity

Normalize it to Third Normal Form. Show all the necessary step and explanation for first and
second normal form too.

In its current state, this table violates the first normal form (1NF) because it allows for repeating groups.
For example, if a customer places multiple orders, their name and address information is repeated in
.each row of the table. This can lead to data redundancy and inconsistency

)marks 3 (

First Normal Form (1NF): ( 3 Marks)

To normalize the table to 1NF, we can split it into two separate tables: one for customer information
:and one for order information. The customer table would have the following columns

CustomerID (primary key)


CustomerName

CustomerAddress

CustomerCity

CustomerState

:The order table would have the following columns

OrderID (primary key)

CustomerID (foreign key)

OrderDate

OrderTotal

We can then eliminate the repeating groups by creating a new table called "OrderItems" with the
:following columns

OrderID (foreign key)

OrderItem

OrderQuantity

This ensures that each piece of information is only listed once in the database, and allows for easier
.management of customer and order data

Second Normal Form (2NF): ( 3 Marks)

To normalize the table to 2NF, we need to ensure that each non-key column in the order table is fully
dependent on the primary key (OrderID). In its current state, the "OrderTotal" column is dependent on
both the "OrderID" and "OrderItem" columns. To resolve this, we can create a new table called
:"OrderItemDetails" with the following columns

OrderID (foreign key)

OrderItem

ItemPrice

OrderQuantity

This separates the item price and quantity from the order total, ensuring that the order total is only
.dependent on the order ID
Third Normal Form (3NF): ( 6 Marks)

To normalize the table to 3NF, we need to ensure that there are no transitive dependencies. In its
current state, the "CustomerCity" and "CustomerState" columns are dependent on the
"CustomerAddress" column. To resolve this, we can create a new table called "CustomerAddress" with
:the following columns

CustomerID (foreign key)

AddressLine1

AddressLine2

City

State

ZipCode

We can then remove the "CustomerAddress", "CustomerCity", and "CustomerState" columns from the
:customer table, and instead include a foreign key reference to the "CustomerAddress" table

CustomerID (primary key)

CustomerName

CustomerAddressID (foreign key)

This ensures that each piece of information is only listed once in the database and allows for easier
.management of customer address data

Question Two: [15 Marks]

Consider the following grade report of a student in different courses. The first part of the report
contains general details of the student such as ID of the student, name of the student, department
code, and department name. The second part of the report contains the details of the courses in
which the student obtained a grade. The Id of the course, name of the course, Id of the teacher,
name of the teacher, country of the teacher and the grade obtained by the student in the course is
.given in this part

(a) Normalize the report into 0NF, 1NF, 2NF and 3NF. Show the complete relations with the
given data in each normal form. [11 marks]
Student Grade Report

Student ID: S8799 Student Name: Asma

Department Code: CS Department Name: Computer Studies


TeacherNam TeacherId
Grade TeacherCountry CourseName CourseCode
e

Introduction to
A Jordan Dr.Wael T1 Computers CS01

+B Oman Dr.Talib T2 Networks CS04

B Jordan Dr.Wael T1 Web Technology CS09

.Note: Grade means the grade obtained by the student in a course

(b) List primary keys & foreign keys (if any) of all tables in 3NF in the following format.

[4 marks]

Table Name Primary key Foreign key

ANSWER
)a(
Un-normalized Form - 1 mark

S_Code SNa DCode DNam C_Co CName TI TNa TCty Gra


me e de d me de

S8799 Asm CS Compu Introduct


a ter ion to
Studies Compute T Dr.W Jord
CS01 rs 1 ael an A
S8799 Asm CS Compu
a ter Network T Dr.T Om
Studies CS04 s 2 alib an +B

S8799 Asm CS Compu Web


a ter Technol T Dr.W Jord
Studies CS09 ogy 1 ael an B

First Normal Form-2 marks

Table 1 [1 mark]

S_Code S DCode DN
N am
a e
m
e

S8799 A CS Co
s mp
m uter
a Stu
dies

Table 2 [1 mark]

S_Code C_Co CName TI TNam TCty Gra


de d e de

S8799 Introducti
on to
Compute T Dr.W Jord
CS01 rs 1 ael an A

S8799 T Dr.Ta Oma


CS04 Networks 2 lib n +B
S8799 Web
Technolo T Dr.W Jord
CS09 gy 1 ael an B

Second Normal Form-3 marks

Table 1 [1 mark]

S_Code S DCode DN
N am
a e
m
e

S8799 A CS Co
s mp
m uter
a Stu
dies

Table 2 [1 mark]

S_Code C_ Gr
Co a
de d
e

S8799 CS
01 A

S8799 CS B
04 +

S8799 CS
09 B

Table 3 [1 mark]
C_Code CName TId TName TCty

Introduction
to
CS01 Computers T1 Dr.Wael Jordan

CS04 Networks T2 Dr.Talib Oman

Web
CS09 Technology T1 Dr.Wael Jordan

Third Normal Form-5 marks

Table name: STUDENT [1 mark]

S_Code S DCode
N
a
m
e

S8799 A CS
s
m
a

Table name: DEPARTMENT [1 mark]

DCode DN
am
e

CS Co
mp
uter
Stu
dies

Table name: GRADE [1 mark]


S_Code C_ Gr
Co a
de d
e

S8799 CS
01 A

S8799 CS B
04 +

S8799 CS
09 B

Table name: COURSE [1 mark]

C_Code CName TId

Introduction
to
CS01 Computers T1

CS04 Networks T2

Web
CS09 Technology T1

Table name: TEACHER [1 mark]

TId TName TCty

T1 Dr.Wael Jordan

T2 Dr.Talib Oman

)0. 5 *8 = 4 marks( )b(


Table Name Primary key Foreign key
STUDENT S_Code DCode

DEPARTMENT DCode --

GRADE S_Code + C_Code S_Code, C_Code

COURSE C_Code TId

TEACHER TId --

Question Two: [15 Marks]

Consider the following position report of a student club in different competitions. The first part
of the report contains general details of the club such as code of the club, name of the club,
university code, and university name. The club participates in different competitions. The second
part of the report contains the details of the competitions in which the club participated. The Id of
the competition, name of the competition, Id of the venue, name of the venue, city of the venue
.and the position won by the club in that competition is given in this part

(a) Normalize the report into 0NF, 1NF, 2NF and 3NF. Show the complete relations with the
given data in each normal form. [11 marks]

Position report of a student club in different competitions

Club Code: C001 Club Name: Winners

University Code: AOU University Name: Arab Open University


VenueId CompetitionNam CompetitionI
Position VenueCity VenueName
e d

Student
First Kuwait Al Jahra V1 Conference CP3

Student
Third Bahrain Manama V2 Symposium CP2

First Bahrain Manama V2 Hash Code CP1

.Note: Position means the position obtained by the club in a competition


(b) List primary keys & foreign keys (if any) of all tables in 3NF in the following format.

[4 marks]

Table Name Primary key Foreign key

ANSWER
)a(
Un-normalized Form - 1 mark

C_Code CNam UCode UNam CP CPNam V VNam VCity Pos


e e Id e Id e

C001 Winne AOU Arab CP Student V Al Kuw Firs


rs Open 3 Confere 1 Jahra ait t
Univer nce
sity

C001 Winne AOU Arab CP Student V Mana Bahr Thi


rs Open 2 Sympos 2 ma ain rd
Univer ium
sity

C001 Winne AOU Arab CP Hash V Mana Bahr Firs


rs Open 1 Code 2 ma ain t
Univer
sity

First Normal Form-2 marks


Table 1 [1 mark]

C_Code CNam UCode UNam


e e

C001 Winn AOU Arab


ers Open
Unive
rsity

Table 2 [1 mark]

C_Code CPI CPName VI VNam VCity Pos


d d e

C001 CP Student V Al Kuwa First


3 Conferen 1 Jahra it
ce

C001 CP Student V Mana Bahra Thir


2 Symposi 2 ma in d
um

C001 CP Hash V Mana Bahra First


1 Code 2 ma in

Second Normal Form-3 marks

Table 1 [1 mark]

C_Code CNam UCode UNam


e e

C001 Winn AOU Arab


ers Open
Unive
rsity
Table 2 [1 mark]

C_Code C Po
PI s
d

C001 C Fir
P st
3

C001 C Th
P ir
2 d

C001 C Fir
P st
1

Table 3 [1 mark]

CPId CPName VId VName VCity

CP3 Student V1 Al Jahra Kuwait


Conference

CP2 Student V2 Manama Bahrain


Symposium

CP1 Hash Code V2 Manama Bahrain

Third Normal Form-5 marks

Table name: CLUB [1 mark]

C_Code CN UCode
a
m
e

C001 Wi AOU
nn
ers

Table name: UNIVERSITY [1 mark]

UCode UName

AOU Arab
Open
Universi
ty

Table name: POSITION [1 mark]

C_Code C Po
PI s
d

C001 C Fir
P st
3

C001 C Th
P ir
2 d

C001 C Fir
P st
1

Table name: COMPETITION [1 mark]

CPId CPName VId

CP3 Student V1
Conference

CP2 Student V2
Symposium
CP1 Hash Code V2

Table name: VENUE [1 mark]

VId VName VCity

V1 Al Jahra Kuwait

V2 Manama Bahrain

)0. 5 *8 = 4 marks( )b(


Table Name Primary key Foreign key

CLUB C_Code UCode

UNIVERSITY UCode --

POSITION C_Code + CPId C_Code, CPId

COMPETITION CPId VId

VENUE VId --

Question Two: [15 Marks]

Consider the following bill of an art shop. The first part of the bill contains details of the
customer and the salesman. The second part of the report contains the details of the product
purchased.

(a) Normalize the report into 0NF, 1NF, 2NF and 3NF. Show the complete relations with the
given data in each normal form. [10 marks]
Bill report

Customer Id: 790 Customer Name: Ahmed


Customer Address: Muscat
Salesman code: EM003 Salesman Name: Khamis

ProductCod ProductPrice QuantityPurchas


ProductName
e ed

OL988 Oil Painting 35 2

PS032 Pencil Sketch 24 1

PS451 Pencil Sketch 20 1


Note:- QuantityPurchased depends on Customer Id and ProductCode.

b) Write suitable table names resulting in 3NF and list primary keys & foreign keys (if any) of all
tables in 3NF in the following format.

[5 marks]

Table Name Primary key Foreign key

ANSWER
(a)
Un-normalized Form - 1 mark

CustId CustName CustAdd SalesCod SalesName PCode Pname Price Qty


e

790 Ahmed Muscat EM003 Khamis OL988 Oil 35 2


Painting

790 Ahmed Muscat EM003 Khamis PS032 Pencil 24 1


Sketch

790 Ahmed Muscat EM003 Khamis PS451 Pencil 20 1


Sketch

First Normal Form-2 marks

Table 1 [1 mark]

CustId CustName CustAdd SalesCod SalesName


e

790 Ahmed Muscat EM003 Khamis

Table 2 [1 mark]

CustId PCode Pname Price Qty

790 OL988 Oil Painting 35 2

790 PS032 Pencil 24 1


Sketch

790 PS451 Pencil 20 1


Sketch

Second Normal Form-3 marks

Table 1 [1 mark]

CustId CustName CustAdd SalesCod SalesName


e

790 Ahmed Muscat EM003 Khamis

Table 2 [1 mark]

CustId PCode Qty

790 OL988 2

790 PS032 1
790 PS451 1

Table 3 [1 mark]

PCode Pname Price

OL988 Oil Painting 35

PS032 Pencil 24
Sketch

PS451 Pencil 20
Sketch

Third Normal Form-4 marks

Table name: CUSTOMER [1 mark]

CustId CustNam SalesCod


e e

790 Ahmed EM003

Table name: SALESMAN [1 mark]

SalesCod SalesName
e

EM003 Khamis

Table name: PURCHASE [1 mark]

CustId PCode Qty

790 OL988 2

790 PS032 1
790 PS451 1

Table name: PRODUCT [1 mark]

PCode Pname Price

OL988 Oil Painting 35

PS032 Pencil 24
Sketch

PS451 Pencil 20
Sketch

(b) (Suitable table names – 0.25 * 4 = 1 mark, Identifying correct primary key & foreign
key – 0. 5 *8 = 4 marks)

Table Primary key Foreign key


Name

CUSTOMER CustId (0.5 mark) SalesCode (0.5 mark)

SALESMAN SalesCode (0.5 mark) --

PURCHASE CustId + PCode (1 mark) CustId, PCode (1 mark)

PRODUCT PCode (0.5 mark) --

Question Two: [15 Marks]


Answer the following questions related to the accommodation of guests in a hotel as shown
:below

ACCOMMODATION (room_no, guest_no, room_type, room_rate, guest_name,


guest_nationality_code,guest_nationality_name, start_date_of_stay, end_date_of_stay)

:Suppose that the following functional dependencies hold

 guest_no determines guest_name, guest_nationality_code and guest_nationality_name


 guest_nationality_code determines guest_nationality_name
 room_no determines room_type and room_rate
 guest_no and room_no determines start_date_of_stay and end_date_of_stay
a. What is the highest normal form that this relation conforms to and why? [3 Marks]
b. Normalise this relation to 3NF, showing the new relations in the manner the
relation ACCOMMODATION is shown above. Make sure you identify the primary key for each
normalized relation by underlining it [6 Marks]
c. Write simple select SQL queries to produce the required normalized relations [6 marks]

Answer

a. This relation is only in 1NF (1 mark)

It violates the condition for 2NF because guest_name and guest_nationality_code and
guest_nationality_name is only dependent on one part of the primary key (guest_no).
room_type and room_rate is dependent only on one part of the primary key
(room_no)
)marks 2(
b. Normalized relations are shown below: (1.5 marks each)
a. ACCOMMODATION (guest_no, room_no,
start_date_of_stay,end_date_of_stay)
b. GUEST (guest_no, guest_name,guest_nationality_code)
c. GUEST_NATIONALITY (guest_nationality_code, guest_nationality_name)
d. ROOM (room_no, room_type,room_rate)

c. SQL Queries are shown below (1.5 marks each)

 SELECT guest_no, room_no, start_date_of_stay,end_date_of_stay FROM


ACCOMMODATION;
 SELECT guest_no, guest_name,guest_nationality_code FROM GUEST;
 SELECT guest_nationality_code, guest_nationality_name FROM
GUEST_NATIONALITY;
 SELECT room_no, room_type,room_rate FROM ROOM;
Question Two: [15 Marks]
Answer the following questions related to a project allocation of a company as shown below:

PROJECT_ALLOCATION (staff_id, project_code department_id, staff_name,


staff_date_of_birth, staff_salary, department_name, project_code, project_name,
hours_worked)

Suppose that the following functional dependencies hold:

 staff_id determines staff_name, staff_date_of_birth, staff_salary and department_id


 department_id determines department_name
 project_code determines project_name
 staff_id, project_code determines hours_worked
a. What is the highest normal form that this relation conforms to and why? [3 Marks]
b. Normalise this relation to 3NF, showing the new relations in the manner the
relation PROJECT_ALLOCATION as shown above. Make sure you identify the primary
key for each normalized relation by underlining it [6 Marks]
c. Write simple ‘select’ SQL queries to produce the required normalized relations [6
marks]

Answer

a. This relation is only in 1NF (1 mark)


It violates the condition for 2NF because staff_name, staff_date_of_birth, and
staff_salary is only dependent on one part of the primary key (staff_id). Similarly,
project_name is only dependent on one part of the primary key (project_id).
(2 marks)
b. Normalized relations are shown below: (1.5 marks each)
o PROJECT_ALLOCATION (staff_id, project_code, hours_worked)
o STAFF (staff_id, staff_name, staff_date_of_birth, staff_salary, department_id)
o PROJECT (project_code, project_name)
o DEPARTMENT (department_id, department_name)

c. SQL Queries are shown below (1.5 marks each)


 SELECT staff_id, project_code, hours_worked FROM PROJECT_ALLOCATION ;
 SELECT staff_id, staff_name, staff_date_of_birth, staff_salary, department_id
FROM STAFF;
 SELECT project_code, project_name FROM PROJECT;
 SELECT department_id, department_name FROM DEPARTMENT;
Question Two: [15 Marks]

Consider the following bill of an art shop. The first part of the bill contains details of the
customer and the salesman. The second part of the report contains the details of the product
purchased.

(a) Normalize the report into 0NF, 1NF, 2NF and 3NF. Show the complete relations with the
given data in each normal form. [10 marks]
Bill report

Customer Id: 790 Customer Name: Ahmed


Customer Address: Muscat
Salesman code: EM003 Salesman Name: Khamis

ProductCod ProductPrice QuantityPurchas


ProductName
e ed

OL988 Oil Painting 35 2

PS032 Pencil Sketch 24 1

PS451 Pencil Sketch 20 1


Note:-
QuantityPurchased depends on Customer Id and ProductCode.

b) Write suitable table names resulting in 3NF and list primary keys & foreign keys (if any) of all
tables in 3NF in the following format.

[5 marks]

Table Name Primary key Foreign key


ANSWER
(a)
Un-normalized Form - 1 mark

CustId CustName CustAdd SalesCod SalesName PCode Pname Price Qty


e

790 Ahmed Muscat EM003 Khamis OL988 Oil 35 2


Painting

790 Ahmed Muscat EM003 Khamis PS032 Pencil 24 1


Sketch

790 Ahmed Muscat EM003 Khamis PS451 Pencil 20 1


Sketch

First Normal Form-2 marks

Table 1 [1 mark]

CustId CustName CustAdd SalesCod SalesName


e

790 Ahmed Muscat EM003 Khamis

Table 2 [1 mark]

CustId PCode Pname Price Qty

790 OL988 Oil Painting 35 2

790 PS032 Pencil 24 1


Sketch

790 PS451 Pencil 20 1


Sketch
Second Normal Form-3 marks

Table 1 [1 mark]

CustId CustName CustAdd SalesCod SalesName


e

790 Ahmed Muscat EM003 Khamis

Table 2 [1 mark]

CustId PCode Qty

790 OL988 2

790 PS032 1

790 PS451 1

Table 3 [1 mark]

PCode Pname Price

OL988 Oil Painting 35

PS032 Pencil 24
Sketch

PS451 Pencil 20
Sketch

Third Normal Form-4 marks

Table name: CUSTOMER [1 mark]

CustId CustNam SalesCod


e e

790 Ahmed EM003


Table name: SALESMAN [1 mark]

SalesCod SalesName
e

EM003 Khamis

Table name: PURCHASE [1 mark]

CustId PCode Qty

790 OL988 2

790 PS032 1

790 PS451 1

Table name: PRODUCT [1 mark]

PCode Pname Price

OL988 Oil Painting 35

PS032 Pencil 24
Sketch

PS451 Pencil 20
Sketch

(b) (Suitable table names – 0.25 * 4 = 1 mark, Identifying correct primary key & foreign
key – 0. 5 *8 = 4 marks)

Table Primary key Foreign key


Name

CUSTOMER CustId (0.5 mark) SalesCode (0.5 mark)

SALESMAN SalesCode (0.5 mark) --

PURCHASE CustId + PCode (1 mark) CustId, PCode (1 mark)

PRODUCT PCode (0.5 mark) --


Question Two: [15 Marks]
Answer the following questions related to a project allocation of a company as shown below:

PROJECT_ALLOCATION (staff_id, project_code department_id, staff_name,


staff_date_of_birth, staff_salary, department_name, project_code, project_name,
hours_worked)

Suppose that the following functional dependencies hold:

 staff_id determines staff_name, staff_date_of_birth, staff_salary and department_id


 department_id determines department_name
 project_code determines project_name
 staff_id, project_code determines hours_worked

d. What is the highest normal form that this relation conforms to and why? [3 Marks]
e. Normalise this relation to 3NF, showing the new relations in the manner the
relation PROJECT_ALLOCATION as shown above. Make sure you identify the primary
key for each normalized relation by underlining it [6 Marks]
f. Write simple ‘select’ SQL queries to produce the required normalized relations [6
marks]

Answer

d. This relation is only in 1NF (1 mark)


It violates the condition for 2NF because staff_name, staff_date_of_birth, and
staff_salary is only dependent on one part of the primary key (staff_id). Similarly,
project_name is only dependent on one part of the primary key (project_id).
(2 marks)
e. Normalized relations are shown below: (1.5 marks each)
o PROJECT_ALLOCATION (staff_id, project_code, hours_worked)
o STAFF (staff_id, staff_name, staff_date_of_birth, staff_salary, department_id)
o PROJECT (project_code, project_name)
o DEPARTMENT (department_id, department_name)

f. SQL Queries are shown below (1.5 marks each)


 SELECT staff_id, project_code, hours_worked FROM PROJECT_ALLOCATION ;
 SELECT staff_id, staff_name, staff_date_of_birth, staff_salary, department_id
FROM STAFF;
 SELECT project_code, project_name FROM PROJECT;
 SELECT department_id, department_name FROM DEPARTMENT;

You might also like