Sie sind auf Seite 1von 17

Lecture 7

Systems Analysis and Design

Lecture 8:
Data Modelling:
Converting ER Diagrams to Relational Tables
Introduction to Normalization

Learning Outcomes
Basic conversion rules;
The Optional-Max conversion process;
Introduce relational table normalisation.

Systems Analysis & Design

Lecture 7

Basic Conversion Rules


For 1:1 cardinality: all attributes are
merged into a single table.
For 1:N cardinality: post the identifier
from the one side as an attribute to
the many side.
For N:M cardinality: create a new table
and post the primary keys from each
entity as attributes in the new table.

Null Values
Should be avoided.
Make it difficult to construct & interpret
relational data base queries.

Systems Analysis & Design

Lecture 7

Optional-Max Conversion Rules


There are 9 rules
On completion of these 9 rules a relational
database would be created.

Optional-Max Conversion Rules:


Rule 1
Faculty
FID [PK]
F_Name
L_name

Teach

Course
CID [PK]
C_Name
Credits

Construct an ER
diagram and label the
upper and lower bounds
for relationship degree.

Enroll

All multi-valued
attributes should be
represented as entities.

Has

Students
SID [PK]
F_Name
L_name

Assigned

Stud_Maj

Systems Analysis & Design

Home Address
H_Street
H_City
H_State

Major
Maj_ID [PK]
Description

Locker
LID [PK]
Building

Lecture 7

Optional-Max Conversion Rules:


Rule 2
Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach

In every instance where the lower


bound for relationship degree is 0
and the upper bound is 1,
temporarily label the upper bound
as N.
If the upper bound is greater than 1
(for example, 3, or 10 or N), leave it
as is.

Enroll

Has

Students
SID [PK]
F_Name
L_name

Assigned

Stud_Maj

Home Address
H_Street
H_City
H_State

Major
Maj_ID [PK]
Description

Locker
LID [PK]
Building

Optional-Max Conversion Rules:


Rule 3
Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach

Use the entity name


for each entity as the
table name

Enroll

Faculty
Course
Students
Home_Address
Major
Locker

Systems Analysis & Design

Has

Students
SID [PK]
F_Name
L_name

Assigned

Stud_Maj

Home Address
H_Street
H_City
H_State

Major
Maj_ID [PK]
Description

N
Locker
LID [PK]
Building

Lecture 7

Optional-Max Conversion Rules:


Rule 4

Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach

If an identifier or primary key has


not been selected then select an
identifier for each table.
Faculty (FID)
Course (CID)
Students (SID)
Home_Address (H_Street, H_City, H_State)
Major (Maj_ID)
Locker (LID)

Enroll

Students
SID [PK]
F_Name
L_name

Has

Assigned

Stud_Maj

Home
Address

Locker
LID [PK]
Building

Major
Maj_ID [PK]
Description

H_Street
H_City
H_State

Optional-Max Conversion Rules:


Rule 5
Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach

Take all the attributes that


describe an entity & post them
as column names in the
relational tables.
Faculty (FID, F_Name, L_Name)
Course (CID, C_Name, Credits)
Students (SID, F_Name, L_Name)
Home_Address (H_Street, H_City,
H_State)
Major (Maj_ID, Description)
Home Address
Locker (LID, Building)
H_Street
10

Systems Analysis & Design

H_City
H_State

Enroll

Has

Students
SID [PK]
F_Name
L_name

Assigned

Stud_Maj

Major
Maj_ID [PK]
Description

N
Locker
LID [PK]
Building

Lecture 7

Optional-Max Conversion Rules:


Rule 6
For 1:1 relationships,
merge all the
attributes into a single
table, Name the
relational table

Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach
N

Enroll

Faculty (FID, F_Name, L_Name)


Course (CID, C_Name, Credits)
Students (SID, F_Name, L_Name,
H_Street, H_City, H_State)

Students
SID [PK]
F_Name
L_name

Has

Major (Maj_ID, Description)

Stud_Maj

Locker (LID, Building)

N
Home Address
H_Street
H_City
H_State

11

Assigned

Major
Maj_ID [PK]
Description

Locker
LID [PK]
Building

Optional-Max Conversion Rules:


Rule 7
For 1:N relationships, take the
identifier of the one side of
the 1:N relationship and post
it as an attribute to the
many side. The identifier
posted to the many side is a
foreign key.

Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach
N

Enroll

Faculty (FID, F_Name, L_Name)


Course (CID, C_Name, Credits)
Has

Students (SID,Maj_ID, F_Name,


L_Name, H_Street, H_City, H_State)
Major (Maj_ID, Description)
Locker (LID, Building)

12

Systems Analysis & Design

Students
SID [PK]
F_Name
L_name

Assigned
N

Stud_Maj
Home Address
H_Street
H_City
H_State

Major
Maj_ID [PK]
Description

N
Locker
LID [PK]
Building

Lecture 7

Optional-Max Conversion Rules:


Rule 8
For N:M relationships, create a new
table using the relationship name
as the name for the table.
Faculty (FID, F_Name, L_Name)

Faculty
FID [PK]
F_Name
L_name

Teach (FID, CID)

concatenated
key

Course
CID [PK]
C_Name
Credits

Teach

C_Enroll

Course (CID, C_Name, Credits)

intersection
table

Enroll

Enroll (CID, SID,)


S_Enroll

Students (SID, Maj_ID F_Name,


L_Name, H_Street, H_City, H_State)

Students
SID [PK]
F_Name
L_name

Has

Major (Maj_ID, Description)


Assigned (SID, LID)
Locker (LID, Building)

Stud_Maj
Major
Maj_ID [PK]
Description

Home
Address
H_Street
H_City
H_State

13

Assigned

N
Locker
LID [PK]
Building

Optional-Max Conversion Rules: Rule 9


Take any additional attributes and post them as column names in the appropriate
relational table. If there are any composite attributes in the relational table
definition, decompose them into simple attributes.
Faculty (FID, F_Name, L_Name)
Teach (FID, CID)

Faculty
FID [PK]
F_Name
L_name

Course
CID [PK]
C_Name
Credits

Teach
N

C_Enroll

Course (CID, C_Name, Credits)

Enroll

Enroll (CID, SID, Grade)


S_Enroll

Students (SID, Maj_ID F_Name,


L_Name, H_Street, H_City, H_State)

Has

Major (Maj_ID, Description)


Assigned (SID, LID, Building)
Locker (LID, Building)

14

Systems Analysis & Design

Students
SID [PK]
F_Name
L_name

Stud_Maj
Home
Address
H_Street
H_City
H_State

Major
Maj_ID [PK]
Description

Assigned
N

N
Locker
LID [PK]
Building

Lecture 7

Optional-Max Conversion Rules


Summary
Optional-Max Conversion Rules
Rule 1

Construct ERD

Rule 2

Change 0:1 to 0:N

Rule 3

Use entity name as Table name

Rule 4

Select and write an identifier for each table

Rule 5

Write down attributes as column names

Rule 6

Merge 1:1 relationships

Rule 7

For 1:N relationships place key from one


side to the many side

Rule 8

For N:M create a new table using


relationship name

Rule 9

If additional attribute exist, place in


appropriate table

15

Normalization
Normalization is a technique for producing a set of
relations with desirable properties, given the data
requirements of an enterprise.
The process of normalization is a formal method that
identifies relations based on their primary or candidate
keys and the functional dependencies among their
attributes.
16

Systems Analysis & Design

Lecture 7

Normal forms

The 4 most commonly used normal


forms are:

First normal form (1NF)


Second normal form (2NF)
Third normal form (3NF)
Boyce-Codd normal form (BCNF)

17

Normal forms
Unnormalized relation
Remove repeating
groups

1NF
Remove partial
dependencies

2NF
Remove transitive
dependencies

3NF
18

Systems Analysis & Design

Lecture 7

Unnormalized form
WHNo WHLoc

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

1001

Hammer

10.99

Hardware

06

1002

Screwdriver

03.99

Hardware

08

1010

Wood Drill

30.49

ET

Electrical

10

1001

Hammer

10.99

Hardware

01

4001

Stepladder

49.99

Hardware

02

Ilford

30

Exeter

19

First normal form (1NF)

First normal form requires that repeating groups must be


removed

(WHNo, WHLoc, (ProductNo, PDesc, Price, PCode,


CDesc, Qty)).
WHNo

WHLoc

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

Ilford

1001

Hammer

10.99

Hardware

06

1002

Screwdriver

03.99

Hardware

08

1010

Wood Drill

30.49

ET

Electrical

10

1001

Hammer

10.99

Hardware

01

4001

Stepladder

49.99

Hardware

02

30

Exeter

Repeating Group
20

Systems Analysis & Design

10

Lecture 7

First normal form (1NF)

WAREHOUSE(WHNo, WHLoc).
STOCK(WHNo, ProductNo, ProductDesc, Price, PCode,
CDesc, Qty).

The duplication of WHNo in both serves to establish the


relationship, or link, between the two entity types.

Neither WHNo nor ProductNo alone would be sufficient to


uniquely identify occurrences of STOCK.

It would be possible to reconstitute the original i.e. identify


all the occurrences of STOCK that are related to any given
occurrence of WAREHOUSE

21

First normal form (1NF)


Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock
WHNo

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

1001

Hammer

10.99

Hardware

06

10

1002

Screwdriver

03.99

Hardware

08

10

1010

Wood Drill

30.49

ET

Electrical

10

30

1001

Hammer

10.99

Hardware

01

30

4001

Stepladder

49.99

Hardware

02

22

Systems Analysis & Design

11

Lecture 7

First normal form (1NF)


Insertion
To insert a new product into
the entity STOCK,
Need to know what warehouse
it is supplied from.

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock
WHNo

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

1001

Hammer

10.99

Hardware

06

10

1002

Screwdriver

03.99

Hardware

08

10

1010

Wood Drill

30.49

ET

Electrical

10

30

1001

Hammer

10.99

Hardware

01

30

4001

Stepladder

49.99

Hardware

02

23

First normal form (1NF)


Deletion
If warehouse 30 is deleted,
all the details of Product 4001
will also be deleted

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock
WHNo

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

1001

Hammer

10.99

Hardware

06

10

1002

Screwdriver

03.99

Hardware

08

10

1010

Wood Drill

30.49

ET

Electrical

10

30

1001

Hammer

10.99

Hardware

01

30

4001

Stepladder

49.99

Hardware

02

24

Systems Analysis & Design

12

Lecture 7

First normal form (1NF)

Editing
same price will be charged for
a product regardless of where
it is supplied from.
If price of hammers at
WHNo10 = 11.99, the price at
WHNo30 will still be = 10.99.
This will make the data
inconsistent.

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock
WHNo

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

1001

Hammer

10.99

Hardware

06

10

1002

Screwdriver

03.99

Hardware

08

10

1010

Wood Drill

30.49

ET

Electrical

10

30

1001

Hammer

10.99

Hardware

01

30

4001

Stepladder

49.99

Hardware

02

25

Clearly, WAREHOUSE is already in 2NF


(Why? Because all attributes fully depend on the
entire key, WHNo; none of the attributes can
depend on part of a WHNo).
Warehouse

WHNo

WHLoc

10

Ilford

30

Exeter

26

Systems Analysis & Design

13

Lecture 7

However, there are partial dependencies in STOCK.


ProductNo ProductDesc, Price, PCode,
CDesc.
Therefore, these attributes depend on only part of
the key, i.e. they depend on ProductNo and NOT
WHNo ProductNo together.
Stock
WHNo

ProductNo

ProductDesc

Price

PCode

CDesc

Qty

10

1001

Hammer

10.99

Hardware

06

10

1002

Screwdriver

03.99

Hardware

08

10

1010

Wood Drill

30.49

ET

Electrical

10

30

1001

Hammer

10.99

Hardware

01

30

4001

Stepladder

49.99

Hardware

02

27

Second normal form (2NF)


"all attributes, which are not part of the primary key, must be fully
functionally dependent on the whole of the key".

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock

Product

WHNo

ProductNo

Qty

ProductNo

ProductDesc

Price

PCode

CDesc

10

1001

06

1001

Hammer

10.99

Hardware

10

1002

08

1002

Screwdriver

03.99

Hardware

10

1010

10

30

1001

01

1010

Wood Drill

30.49

ET

Electrical

30

4001

02

4001

Stepladder

49.99

Hardware

28

Systems Analysis & Design

14

Lecture 7

Second normal form (2NF)


Insertion
In PRODUCT,
To insert a potentially new
product code you will need to
insert details of a product,
because the key ProductNo
would be NULL or empty.
This is unacceptable.

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock

Product

WHNo

ProductNo

Qty

ProductNo

ProductDesc

Price

PCode

CDesc

10

1001

06

1001

Hammer

10.99

Hardware

10

1002

08

1002

Screwdriver

03.99

Hardware

10

1010

10

30

1001

01

1010

Wood Drill

30.49

ET

Electrical

30

4001

02

4001

Stepladder

49.99

Hardware

29

Second normal form (2NF)


Deletion
In PRODUCT, if you want to
stop selling wood drills,
you need to delete the row
for wood drill i.e. where
ProductNo = 1010.

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock

Product

When you do this, the fact


that the product code 'ET'
and its description
Electrical exist, is now lost.

WHNo

ProductNo

Qty

ProductNo

ProductDesc

Price

PCode

CDesc

10

1001

06

1001

Hammer

10.99

Hardware

10

1002

08

1002

Screwdriver

03.99

Hardware

10

1010

10

30

1001

01

1010

Wood Drill

30.49

ET

Electrical

30

4001

02

4001

Stepladder

49.99

Hardware

30

Systems Analysis & Design

15

Lecture 7

Second normal form (2NF)


Editing
In PRODUCT, change the
code description for
stepladders from Hardware
to Paint.

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Stock

Product

The product code H will


have a description of Paint
for this row, and a
description of Hardware
everywhere else. This leads
to inconsistency in the data.

WHNo

ProductNo

Qty

ProductNo

ProductDesc

Price

PCode

CDesc

10

1001

06

1001

Hammer

10.99

Hardware

10

1002

08

1002

Screwdriver

03.99

Hardware

10

1010

10

30

1001

01

1010

Wood Drill

30.49

ET

Electrical

30

4001

02

4001

Stepladder

49.99

Hardware

31

Transitive dependencies

ProductNo

PCode

CDesc

CDesc is not dependent on ProductNo. Its having


transitive dependecies with ProductNo
Normalisation requires that more new entity
types be formed to remove the transitive
dependencies, but that their key (PCode in this
case) must also be retained in the original entity
type

32

Systems Analysis & Design

16

Lecture 7

Third normal form (3NF)


"Entity types are in 3NF when all attributes which are not part of the key are
functionally dependent on the key, the whole key and nothing but the
key".

Stock

Warehouse
WHNo

WHLoc

10

Ilford

30

Exeter

Product

33

ProductNo

PDesc

Price

PCode

1001

Hammer

10.99

1002

Screwdriver

03.99

1010

Wood Drill

30.49

ET

4001

Stepladder

49.99

WHNo

ProductNo

Qty

10

1001

06

10

1002

08

10

1010

10

30

1001

01

30

4001

02

Product_Code
PCode

CDesc

Hardware

ET

Electrical

Summary Normalisation
Unnormalized relation
Remove repeating
groups

1NF

Remove partial
dependencies

2NF
Remove transitive
dependencies

3NF
34

Systems Analysis & Design

17

Das könnte Ihnen auch gefallen