Escolar Documentos
Profissional Documentos
Cultura Documentos
MATRIC.NO : D20161074130
CLASS : AT20
GROUP : A [WEDNESDAY]
ASSIGNMENT 2
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.
c. The following tables form part of a database held in a relational DBMS. Answer all
questions below based on the following tables.
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.
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 -
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
ORDER
ORDER_LINE
002 D472 12
003 D576 20
004 A768 14
3
PRODUCT
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.
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.
CSN=CustNo
4
ii. Produce sample tables for these relations that observe the relational integrity
rules.
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
AUTHOR_TITLE
au_id title_id
213-46-8915 BU2075
TITLE
AUTHOR
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’.
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
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
e. Describe briefly about First Normal Form (1 NF) and Third Normal Form (3 NF) and use the
example to support your answer.
11
- Has no transitive functional dependency
- Table must be in 2NF
- Example:
Job_class Charge_hour
Job (JobClass, ChargeHour)
Employee (EmpNo, EmpName, Job)
Project (ProjectNo, ProjectName)
Assignment (ProjectNo, EmpNo, AssignmentHour)
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
12
Dosage, Method, UnitPerDay, SDate, FDate
2NF
Identify partial dependency
3NF
Identify transitive dependency
13