Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
3
1. FIRST NORMAL FORM (1NF)
5
STEPS TO MAKE THIS RELATION INTO 1NF.
6
2. Make sure the order of the rows and columns
doesn’t matter. If the order of the rows matters,
add a column to record the information implied by
their positions. In this example, make a new
Priority column and explicitly list the passengers’
priorities.
7
3. Make sure each column holds a single data type.
If a column holds more than one type of data, split it
into multiple columns, one for each data type. In
this case, list the connecting cities, and don’t even
record the number of cities. Just count them when
necessary.
8
4. Make sure no two rows can contain identical
values. If two rows contain identical values, add a
field to differentiate them. In this case, add a
CustomerId column so you can tell the customers
apart.
9
10
5. Make sure each column contains a single value. If a column
holds multiple data values, split them out into a new table. Make
a new Connections table and move the connection data there.
To tie those records back to their original rows in this table, add
columns that correspond to the primary key columns in the
original table (CustomerId and Date).
11
6. Make sure multiple columns don’t contain repeating groups.
In this example, you need to think about the two city fields
and decide whether they contain distinguishable values.
12
CLASS WORK
13
1 SOLUTION
S
14
PRIME ATTRIBUTE, FULL FUNCTIONAL DEPENDENCY
AND TRANSITIVE FUNCTIONAL DEPENDENCY
A FD X Y is a full functional dependency if the FD does not hold when any attribute
from X is removed
Example: (roll) (name)
It is non-transitive otherwise 15
Example: (roll) (name)
2. SECOND NORMAL FORM (2NF)
A relation is in 2NF if
Every non-prime attribute is fully functionally dependent on every
candidate key
(Or)
(Or)
1. It is in 1NF.
2. All of the non-key fields depend on all of the key
fields. 16
If a table is not in second normal form, remove
those non–key fields that are not dependent on
the whole of the primary key. Create another
table with these fields and the part of the primary
key on which they do depend.
17
PROBLEM
Consider (Id, ProjId, Hrs, Name, ProjName) with FDs:
19
PROBLEM:3
20
CLASS WORK
1.
21
2.
22
3.
R = {part_no, part_description, part_price,
supplier_id, supplier_address}
23
4.
24
SOLUTION
1.
S
25
2.
26
3.
part_no → part_description
supplier_id → supplier_address
{part_no, supplier_id} →
part_price
27
4.
28
3. THIRD NORMAL FORM (3NF):
A relation is in 3NF if
It is in 2NF, and
No non-prime attribute is transitively functionally dependent on
the candidate keys
Alternatively, for every FD X Y, either
It is trivial, or
X is a superkey, or
Every attribute in Y - X is prime
30
PROBLEM :2
31
CLASS WORK
Make the following relations into 3NF
1.
Student (Roll no, name, dept, year,
hostelname)
- If students in a given year are all put in one hostel then year and the hostel
are functionally dependent
- If all students of year 1 are moved to another hostel many tuples need to be
changed.
32
2.
Employee (empcode, name, salary, project no,
termination date of project)
3.
Passenger (Ticket no, Passenger name, Train no,
Departure time, Fare)
4.
33
5.
6.
34
7.
8.
35
SOLUTION
S
1.
Student ( Roll no, name, dept, year)
Hostel (year, hostel)
2.
Employee(empcode,name,salary,projectno)
Project( Projectno ,termination date of project)
3.
Passenger (Ticket no, Passenger name, Train no, Fare)
Train details (Train no, departure time)
36
4.
5.
37
6.
7.
8.
Student_id, Student_name,
DOB, Zip, Zip, Street, city, state
38
3 NF ALL TOGETHER
PROBLEM
39
CONT…
2 NF:
3NF:
PROJECT (PROJ_NUM, PROJ_NAME)
ASSIGN (PROJ_NUM, EMP_NUM, HOURS)
EMPLOYEE (EMP_NUM, EMP_NAME,
JOB_CLASS) JOB (JOB_CLASS, CHG_HOUR)
40
CLASS WORK
41
SOLUTION
42
• Second Normal Form (2NF)
43
•Third Normal Form
(3NF)
44
SUMMAR
Y
Informally
1NF: All attributes depend on the key
2NF: All attributes depend on the whole key
3NF: All attributes depend on nothing but the key
Tests
1NF: The relation should have no multivalued attributes or nested relations
2NF: For a relation where candidate key contains multiple attributes, no nonkey
attribute should be functionally dependent on a part of the candidate key
3NF: The relation should not have a nonkey attribute functionally determined by
a set of nonkey attributes.
Remedies
1NF: Form new relations for each multi-valued attribute or nested relation.
2NF: Decompose and set up a relation for each partial key with its dependent(s);
retain the primary key and attributes fully dependent on it. 45 3NF: Decompose
and set up a relation for each nonkey attribute with nonkey attributes