You are on page 1of 13

RELATIONAL MODEL TOPIC

a. Define the two (2) principal integrity rules for the relational model. Discuss why it is
desirable to enforce these rules. You may use some examples to support your answer.

i. Entity integrity-In a base table, no column of a primary key can be null.


ii. Referential integrity-If a foreign key exists in a table, either the foreign key value must
match a candidate key value of some record in its home table or the foreign key value
must be wholly null.

b. Describe what is relational integrity of NULL represents for?

If a foreign key exists in a relation, either the foreign key value must match a candidate
key value of some tuple in its home relation or the foreign key value must be wholly
null.

c. The following tables form part of a database held in a relational DBMS. Answer all
questions below based on the following tables.

Hotel (hotelNo, hotelName, city)


Room (roomNo, hotelNo, type, price)
Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
Guest (guestNo, guestName, guestAddress)

where Hotel contains hotel details;


Room contains room details for each hotel;
Booking contains details of the bookings for each room in each hotel;
and Guest contains guest details.

i. What is the difference between primary key and foreign key? Define each primary
key and foreign key in the table provided to shows the relationship of the table.

Primary key is an attribute (or a combination of attributes) that uniquely identifies


any given entity (row) while foreign key is An attribute whose values match
primary key values in the related table
Table Name Primary Key Foreign Key

Hotel hotelNo NULL

Room roomNo hotelNo

Booking hotelNo, guestNo roomNo

Guest guestNo NULL

ii. Produce sample table for each relation that observe the relational integrity rules.
Suggest some enterprise constraints that would be appropriate for this schema.

Hotel

hotelNo(PK) hotelName City

1001 Vistana Hotel Kuantan, Pahang

1002 Sutra Beach Resort Kuala Terengganu, Terengganu

Room

roomNo (PK) hotelNo(FK) Type Price

300 1001 Deluxe Bed RM300

200 1002 Double Bed RM250

Booking

HotelNo(PK) GuestNo(PK) dateFrom dateTo RoomNo(FK)

1001 3600 15/06/2017 18/06/2017 300

1002 1415 17/06/2017 20/06/2017 200

Guest

GuestNo(PK) guestName guestAddress

3600 Nor Fadzliana Shah Alam, Selangor

1415 Azwan Jengka, Pahang


Student should provide some sample tables, observing entity and referential
integrity. In particular, ensure the uniqueness for the composite primary keys of the
Room and Booking tables.

Some enterprise constraints may be:

There can be no two bookings for the same room in the same hotel on the same
day.
For the Booking relation, dateFrom must be before dateTo.
Room price must be greater than 0 and less than RM150

d. The following figure form part of an ER Model of a Customer Invoice Module. Convert
the following ER model into relations in a relational data model. You can assume that each
attributes contains (at least) a suitably-named attribute containing a unique identifying
number

Customer

Cust_ID(PK) Cust_name Cust_add

104 Nor Fadzliana Rawang Perdana 2, Selangor

105 Azwan Rawang Putra, Selangor

Order

Order_ID(PK) Order_date Cust_ID(FK)

1114 25/05/2017 104

1115 30/05/2017 105

Product

Product_ID Product_desc Unit_price

SB6001 High RM1.00

SA5021 Low RM2.50

HE3002 Low RM6.00


Order_line

Order_ID Product_ID Order_Qtty


1114 SB6001 5

1115 HE3002 1

e. The following relational data model form part of a database held in a relational DBMS.
Answer all questions below based on the following schema. CUSTOMER(CSN, Name,
Tel, Add, ICNo)
VEHICLE(PlateNo, VehicleID, Status, TtlFuel)
VEHICLE_RENTAL(CSN, PlateNo, DateRent, DateReturn, Charge)
VEHICLE_TYPE(VehicleID, VehcCategory, VehcType, CC)

i. Define each primary key and foreign key in the schema provided to show the
relationship of the table. State NULL if the table is not having any primary or
foreign key.

Table Name Primary key Foreign key


Customer CSN,ICNo NULL

Vehicle PlateNo VehicleID

Vehicle_rental CSN,PlateNo PlateNo

Vehicle_type VehicleID NULL

ii. Produce sample tables for these relations that observe the relational integrity
rules.

Customer

CSN (PK) Name (PK) Tel Add ICNo(FK)

001 Nor Fadzliana 01112300141 Shah Alam, Selangor 950909065168

Vehicle

PlateNo (PK) VehicleID (FK) Status TtlFuel

WA3600 IRIZ.T all driver 5


Vehicle_Rental

CSN(PK) PlateNo(PK) DateRent DateReturn Charge

001 WA3600 18/5/2017 18/5/2017 RM10

Vehicle_type

VehicleID(FK) VehcCategory VehcType CC

IRIZ.T CAR PROTON IRIZ 1.5

i. Figure 1 above shows the relational tables for a simple bibliographic database that stores
information about book title, authors, and publishers.

i. Define each primary key and foreign key show in the table provided to shows the
relationship of the table.

Table Name Primary key Foreign key

Author Author_ID Null

Tittle Tittle_ID Pub_ID

Publisher Pub_ID Pub_name

Author_tittle Tittle_ID Author_ID

ii. Relational tables can be expressed concisely by eliminating the sample data and
showing just the table name and the column names. From all tables provided, list out
the entities, attributes, primary keys and foreign key in logical data model form.
iii. From relational table provided, find author name who published book for Algodata
InfoSystems (Hint: you can use any method to retrieve this info. Show in details)

SQL

a. Describe a situation in which you would need to write a query using the HAVING clause.

Filters group
Column names in HAVING clause must also appear in GROUP BY list or
be contained within an aggregate function.

b. Explain the function of each of the following clauses in the SELECT statement.

i. FROM- Specifies the table or tables to be used.


ii. WHERE- restricts the selection of rows based on a condition expression
iii. GROUP BY- Group the selected rows based on one or more attributes
iv. HAVING-Restricts the selection of grouped rows based on a condition
v. ORDER BY-Orders the selected rows

c. The following tables form part of a database held in a relational DBMS. Based on the
following table structure, create SQL statement for each of the following questions. (Hint:
For this question, you need to prepare the database and tables in order to manipulate the
data. You need to print screen each of the output and the coding to retrieve the output).

i. List full details of all students under programme AT20, alphabetically ordered by
name.

Table Student

Table Lecturer
Table Appointment

ii. How many students register for Appointment System?

iii. List the names and matric number of all students register for appointment on 3:00
pm.
iv. List the names of students register for appointment with Puan Haliza.

v. Insert new record into table Appointment using following data.


ApmntNo = 5
StudentName = Ahmad Ali
StaffName = Mohd Kamal Ariffin
ApmntDate = 6/5/2017
ApmntTime = 9:00 am

vi. Change the record of student named Chong Wai into new data as following:
StudentName = Chong Wai Chi
Address = Alor Star, Kedah
ProgrammeID = AC10

NORMALIZATION

a. Describe the concept of functional dependency. Use simple example to support your answer.

Functional dependency describes the relationship between attributes in a relation.


For example, if A and B are attributes of relation R, B is functionally dependent on A (denoted
A B), if each value of A in R is associated with exactly one value of B in R.

b. Relations that contain redundant information may potentially suffer from update
anomalies. Describe the types of update anomalies and use your own example to support
your answer.

A major aim of relational database design is to group attributes into relations so as to


minimize information redundancy and thereby reduce the file storage space required by the
base relations. Another serious difficulty using relations that have redundant information is
the problem of update anomalies. These can be classified as insertion, deletion, or
modification anomalies.
c. What are the main characteristics of functional dependencies that are used when normalizing
a relation?

i. Have a one-to-one relationship between attribute(s) on the left and right-hand side of a
dependency
ii. Hold for all time
iii. Are non-trivial

d. Define normalization terminology and describe the purpose of normalizing data.

Normalization is a technique for producing a set of relations with desirable properties, given
the data requirements of an enterprise. Normalization supports database designers by
presenting a series of tests, which can be applied to individual relations so that a relational
schema can be normalized to a specific form to prevent the possible occurrence of update
anomalies.

e. Describe briefly about First Normal Form (1 NF) and Third Normal Form (3 NF) anduse the
example to support your answer.

First Normal Form (1 NF)


As per First Normal Form, no two Rows of data must contain repeating group of information
i.e each set of column must have a unique value, such that multiple columns cannot be used
to fetch the same row. Each table should be organized into rows, and each row should have
a primary key that distinguishes it as unique.

The Primary key is usually a single column, but sometimes more than one column can be
combined to create a single primary key. For example consider a table which is not in First
normal form

Student Table:

Student Age Subject

Adam 15 Biology, Maths

Alex 14 Maths

Stuart 17 Maths

In First Normal Form, any row must not have a column in which more than one value is
saved, like separated with commas. Rather than that, we must separate such data into
multiple rows.
Student Table following 1NF will be:
Student Age Subject

Adam 15 Biology

Adam 15 Maths

Alex 14 Maths

Stuart 17 Maths

Third Normal form applies that every non-prime attribute of table must be dependent on
primary key, or we can say that, there should not be the case that a non-prime attribute is
determined by another non-prime attribute. So this transitive functional dependency should
be removed from the table and also the table must be in Second Normal form. For example,
consider a table with following fields.
Student_Detail Table :

Student_id Student_name DOB Street city State Zip

In this table Student_id is Primary key, but street, city and state depends upon Zip. The
dependency between zip and other fields is called transitive dependency. Hence to
apply 3NF, we need to move the street, city and state to new table, with Zip as primary key.
New Student_Detail Table:

Student_id Student_name DOB Zip

Address Table:

Zip Street city state

f. Fields in the original data table will be as follows:

PatientNo, fName, WardNo, WardName, BedNo, DrugNo, DrugName, Desc, Dosage,


Method, UnitPerDay, SDate, FDate
Think of this as the baseline one large table.

Describe and illustrate the process of normalizing data from the form shown in the
above table to 3NF. State your assumptions about the data shown in this table. Show
the process of normalizing the table step by step.

First Normal Form (1NF)


Patient (PatientNo, fName, WardNo, WardName, BedNo, DrugNo, DrugName, Desc,
Dosage, Method, UnitPerDay, SDate, FDate)

Second Normal Form (2NF)

Partial dependency
PatientNo (fName, WardNo, WardName, BedNo)
DrugNo (DrugName, Desc, Dosage, Method, UnitPerDay)

Patient (PatientNo, fName, WardNo, WardName, BedNo)


Medicine (DrugNo, DrugName, Desc, Dosage, Method, UnitPerDay)
Date (PatientNo, DrugNo, SDate, FDate)

Third Normal Form (3NF)

Transitive dependency
WardNo WardName

Patient (PatientNo, fName, BedNo)


Medicine (DrugNo, DrugName, Desc, Dosage, Method, UnitPerDay)
Date (PatientNo, DrugNo, SDate, FDate)
Ward (WardNo, WardName)

We may assume that a patient is can take two medicine per day. Also, a patient may
can take one medicine only.

You might also like