Exercise 3 To Be Solved
Exercise 3 To Be Solved
Solutions
Definitions
UNF definition: A relation (table) that contains one or more repeating groups.
1NF definition: A relation (table) in which the intersection of each row and column
contains one and only one value.
2NF definition: A relation that is in 1NF and every non-primary key attribute is fully
functional dependent on the primary key.
3NF definition: A relation that is in 1NF and 2NF, and in which no non-primary key
attribute is transitively dependent on the primary key
Transitive Dependency: A condition where A,B and C are attributes of a relation such
that if A B and B C, then C is transitively dependent on A via B (provided that A
is not functionally dependent on B or C).
a) and b)
The table in the example is at least in 1NF (to check for 2NF the primary key needs to
be defined.) Candidate attributes are NIN, Contract No and Company ID), we can
choose NIN and ContractNo as the primary key because this two will be the minimum
attributes required to uniquely identify each row in the table and also will reflect
better the objective of the company which is to keep track record of staff supplied in a
contract to another company.
Given the PK: NIN, ContractNo each non-primary key attribute needs to be checked
for fully functional dependency on the PK:
c)
We need to find dependencies on the PK and on parts of the PK (partial dependencies):
NIN, ContractNo (primary key)
NIN (partial dependency on the PK)
ContractNo (partial dependency on the PK)
Examining each of the remaining attributes, we determine what is the dependency
associated with it:
d) To normalise the table to 2NF, we need to remove the partial dependencies from
the table and locate them in a new table.
ContractNo CompanyID.
CompanyID CompanyLocation.
f)
To normalise to 3NF this transitive dependency needs to be put in a new table with a
copy of the determinant:
And the previous tables are left the way they are because they are 3NF already.
Primary Keys are underlined, foreign keys are marked with an (*).
Using DBML for the first set we can express the relations:
Note:
The foreign keys selection on the tables is arbitrary, once the full tables are
normalised to 3NF, the FK are used to link the tables. The previous 3NF relations
could be also written as: