Você está na página 1de 13

NAME : MARSITA BALQIS BT ZAKARIA

MATRIC.NO : D20161074130

CLASS : AT20

GROUP : A [WEDNESDAY]

ASSIGNMENT 2

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 exist in a table, either the foreign 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?


- Null value is no data entry, but permitted in primary key. Null value can be represent an
unknown attributes value. Can act as a known but missing attribute value. Null value is
“non applicable” condition.

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.

1
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 FOREIGN KEY


Candidate key that selected to uniquely An attribute (or combination of
identify all other attributes value in any attributes) in one table whose value
given row. Cannot contain null entire. must either match the primary key in
another table or be 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.

TABLE NAME PRIMARY KEY FOREIGN KEY

Hotel HotelNo -
Room RoomNo HotelNo
Guest GuestNo -

HotelNo
Booking - RoomNo
GuestNo

Booking
Hotel Room
FK hotelNo
PK HotelNo PK RoomNo
PK RoomNo
HotelName PK hotelNo Guest
PK GuestNo
City Type PK GuestNo
DateFrom
Price GuestName
DateTo
GuestAddress

2
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 CUST_NAME CUST_ADD

100 David Kajang, Selangor


101 Mary Lee Cheras, Selangor
102 Ahmad Albab Semenyih, Selangor

ORDER

CUST_ID ORDER_ID ORDER_DATE

100 002 17-Mac-2017


101 003 4-April-2017
102 004 16-April-2017

ORDER_LINE

ORDER_ID PRODUCT_ID ORDER_QTTY

002 D472 12
003 D576 20
004 A768 14

3
PRODUCT

PRODUCT_ID PRODUCT_DESC UNIT_PRICE

D472 Trouser 18.00


D576 Dress 67.00
A768 T-shirt 36.00

h. 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 NULL


VEHICLE PlateNo VehicleID
VEHICLE_RENTAL CSN PlateNo
VEHICLE_TYPE VehicleID NULL

CSN=CustNo

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

CUSTOMER Vehicle_Rental Vehicle_Type


VEHICLE
PK CSN PK CSN PK VehicleID
PK PlateNo
Name FK PlateNo VechCategory
FK VehicleID
Tel DateRent VechType
Status
Add DateReturn CC
TtlFuel
ICNo Charge

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.

5
TABLE NAME PRIMARY KEY FOREIGN KEY

Author au_id -
Title title_id pub_id
Publisher pub_id -
Author_Title - au_id
title_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.

Author

PK au_id

au_lname

au_fname

PK address

city

state

author_title

FK au_id

FK title_id

TITLE Publisher
PK title_id FK pub_id
title
pub_home
type
city
6
price

PK pub_id
iii. From relational table provided, find author name who published book for Algodata
InfoSystems (Hint: you can use any method retrieve this info. Show in details)

 SELECT

PUBLISHER

pub_id pub_name city

1389 Algodata Info Berkeley

AUTHOR_TITLE

au_id title_id

213-46-8915 BU2075

TITLE

title_id title pub_id

BU2075 You Can Combat Computer Stress! 1389

AUTHOR

au_id au_lname au_fname address city state

213-46-8915 Carson Cheryl 589 Darwin Ln Berkeley CA

7
SQL
a. Describe a situation in which you would need to write a query using the HAVING clause.
- The HAVING clause can be used to restrict rows. It is similar to the WHERE condition
except HAVING can include the aggregate function; the WHERE cannot do this.

- The HAVING clause behaves like the WHERE clause, but is applicable to groups. In this
example, we use the HAVING clause to exclude the groups with the province ‘BC’.

- SELECT au_fname AS ‘Author’s First Name’, province as ‘Province’


FROM Authors
GROUP BY au_fname, province
HAVING province < > ‘BC’

b. Explain the function of each of the following clauses in the SELECT statement.
i. FROM
- The SQL From clause is the source of a rowset to be operated upon in a Data
Manipulation Language (DML) statement. From clauses are very common, and will
provide the rowset to be exposed through a Select statement, the source of values in an
Update statement, and the target rows to be deleted in a Delete statement.

ii. WHERE
- Restrict the selection of row based on a conditional expression

iii. GROUP BY
- Group selected rows based on one or more attributes

iv. HAVING
- Restrict the selection of grouped rows based on a condition

8
v. ORDER BY
- Used to sort output of a SELECT statement
- Can sort by one or more columns and use either an ascending or descending order

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.

9
NORMALIZATION
a. Describe the concept of functional dependency. Use simple example to support your
answer.
- The attributes of a table is said to be dependent on each other when an attribute of a table
uniquely identifies another attribute of the same table.
- Example: Student Details

matric_no name date_of_birth

matric_no name
matric_no date_of_birth

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.
- An update anomaly occurs when data is only partially updated in a database
- A database that hasn’t undergone normalization may reference the same data element in
more than one location
- As these location haven’t been consolidated and reference, we have to make sure each
location is manually updated
- This can cause problems as we then need to spend time searching for and updating each
references t o the data element.
- An example of this is database containing two records, user and mailing list.
John has an email address of john@gmail in the user record
John has the same email address in the mailing list record
John decided to change his email preferences, which in turn updates the user
record for John

10
However, the system did not automatically update the mailing list record, leaving
with two associated email and thus creating inconsistencies within our database.

c. What are the main characteristics of functional dependencies that are used when normalizing a
relation?
- Have a 1:1 relationship between attribute (s) on left and right-hand side of a dependency
- Hold for all time

d. Define a normalization terminolgy and describe the purpose of normalizing data.


- Normalization is to minimize data redundancy
- Purpose:
Eliminating redundant (useless) data
Ensuring data dependencies make sense i.e data is logically stored

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

First Normal Form (1 NF)


- All key attributes are defined
- There are no repeating groups in the table
- All attributes are dependent on primary keys
- Ex: Comp_Project (ProjectNo, ProjectName, EmpNo)

ProjNo ProjName EmpNo EmpName JobClass Charge Hour

18 Amber 114 Alice App Design 98 24.6


25 Star 114 Alice App Design 98 32

Third Normal Form (3 NF)

11
- Has no transitive functional dependency
- Table must be in 2NF
- Example:

Emp_num Job_class Charge_hour

Job_class Charge_hour
Job (JobClass, ChargeHour)
Employee (EmpNo, EmpName, Job)
Project (ProjectNo, ProjectName)
Assignment (ProjectNo, EmpNo, AssignmentHour)

f. The patient medication form for Slim River hospital.

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.

1NF
Identify the primary key

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

12
Dosage, Method, UnitPerDay, SDate, FDate

2NF
Identify partial dependency

PatientNo fName, WardNo, WardName, BedNo


DrugNo DrugName, Desc, Dosage, Method, UnitPerDay, SDate, FDate

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


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

3NF
Identify transitive dependency

WardNo WardName, BedNo


Ward (WardNo, WardName, BedNo)

Patient (PatientNo, fName)


Medicine (DrugNo, DrugName, Desc, Dosage, Method, SDate, FDate)
Unit ( PatientNo, DrugNo, UnitPerDay)
Ward (WardNo, Wardname, BedNo)

13

Você também pode gostar