Vous êtes sur la page 1sur 3

Tutorial on Schema Qualities (Solution)

1. ORDER
(Order_ID, Date, Cust_ID, Cust_Name, State, Item_ID, Item_Descrip, Quantity,
Price)

Primary key: Order_ID

Composite key: Date, Cust_ID, Item_num

FDs:
Cust_ID -> Cust_Name
Cust_ID -> State
Item_ID -> Item_Descrip

Which normal form is the schema in?

Solution: The schema is in the second normal form. There is no non-prime attribute that is
partially functionally dependent to the primary key.

The schema is not in the third normal form because we can identify non-prime attributes that
are transitively dependent to the primary key. For example, Order_ID -> Item_ID ->
Item_Descrip.

What alternative schema would you suggest?

Solution: We perform a normalization on the schema to obtain a schema in third normal form.
(Order_ID, Date, Cust_ID, Item_ID, Quantity, Price)

(Cust_ID, Cust_Name, State)

(Item_ID, Item_Descrip)

 Note that this table is often used as an example of fact table. It is naturally normalized.
2. TIME
(Date, Day, Day_of_Week_id, Day_of_Week, Month_id, Month_Name, Quarter_id,
Quarter_Name)

Primary key: Date

FDs:
Day_of_Week_id -> Day_of_Week
Month_id -> Month_Name
Quarter_id -> Quarter_Name
Month_id -> Quarter_id

Which normal form is the schema in?

Solution: Similar argument to Question 1.

What alternative schema would you suggest?

Solution: We perform a normalization process to produce a schema in the third normal form.
(Date, Day, Day_of_Week_id, Month_id)

(Day_of_Week_id, Day_of_Week)

(Month_id, Month_Name, Quarter_id)

(Quarter_id, Quarter_Name)

 Note that the time table is almost always the dimension table. Even it can be normalized,
TIME table is almost always not be normalized for efficient browsing of data cube.
3. CUSTOMER
(First_Name, Last_Name, FN_Chinese_Telegraph_Code, LN_Chinese_Telegraph_Code,
Gender, Address_lines, City, Country, Tel_Nos, Salary, BDate)

Primary Key: First_Name, Last_Name

FDs:
First_Name -> FN_Chinese_Telegraph_Code
Last_Name -> LN_Chinese_Telegraph_Code
City -> Country

3.1 For programming convenience, add a surrogate key to the relation.

Solution: (CID, First_Name, Last_Name, FN_Chinese_Telegraph_Code,


LN_Chinese_Telegraph_Code, Gender, Address_lines, City, Country, Tel_Nos,
Salary, BDate)

CID is an artificial key. Most RDBMS builds indexes on primary key automatically. A simple key
like CID often leads to better performance.

3.2 Suppose that the company now allows customers to provide their HKIDs (voluntarily). (i)
What are the possible new FDs by introducing HKID to the relation. (ii) Which normal form is
the schema in then? (iii) In this context, is HKID a reasonable primary key?

Solution:

(i) (CID, First_Name, Last_Name, FN_Chinese_Telegraph_Code,


LN_Chinese_Telegraph_Code, Gender, Address_lines, City, Country,
Tel_Nos, Salary, BDate, HKID)

(ii) The relation is of the second normal form.

(iii) Since HKID is provided voluntarily, some customers may not have HKIDs (nullable)
in the database. Due to the entity integrity constraint, the primary key must not be
NULL. Therefore, HKID is NOT a reasonable primary key.

Vous aimerez peut-être aussi