Вы находитесь на странице: 1из 92

Reducing E-R Diagrams to

Tables
Remedios de Dios Bulos
friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* staff WorksFor
Friends
EID {PK} DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD EStNo MANAGES {R}

Controls
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate WorksOn
EBYear 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
1..* 0..* PrNo {PK}
PrName
DeName
USE {R}
JobIs

DeGender DeLastName PrLocation [1..*]


DeBDate DeFirstName
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Objective : Logical Design

Design Relational Schema of a Company


Relational Schema of Company Database
POSITION ( PNo, PName, Salary)
MACHINE( MNo, MDesc, MLocation)
DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)
DEPARTMENT ( DNo, DName, DLocation, MgrEID, MgrStartDate)
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,
ECountry, EGender, EBYear, EBMo, EBDay, EAge, DNo, PNo)
PROJECT ( PrNo, PrName, DNo)
WorksOn ( EID, PrNo, HoursPerMonth )
Friends ( EID1, EID2)
HasPhone ( EID, EPhone )
ProjectLocation ( PrNo, PrLocation )
USE ( EID, PrNo, MNo, UseDate, SHour, SMin, EHour, EMin, HoursPerDay )
EMPLOYEE
Field Data Type Length Required Foreign Key
EID {PK} char 10 Not null
ELastName char 30 Not null
EFirstName char 30 Not null
EMI :PK char 4
EStNo char 5
EStName char 20
ECity char 20 Not null
ECountry char 20 Not null
EGender char 1 Not null
EBYear Date Not null
EBMo Date Not null
EBDay Date Not null
EAge int
DNo char 5 Not null DEPARTMENT
PNo char 5 Not null POSITION
DEPARTMENT
Field Data Type Length Required Foreign Key
DNo {PK} char 10 Not null
DName char 50 Not null
DLocation char 50 Not null
MgrEID char 10 EMPLOYEE
MgrStartDate Date

POSITION
Field Data Type Length Required Foreign Key
PNo{PK} char 10 Not null
PName char 50 Not null
Salary money
PROJECT
Field Data Type Length Required Foreign Key
PrNo{PK} char 10 Not null
PrName char 50 Not null
DNo char 10 Not null DEPARTMENT

MACHINE
Field Data Type Length Required Foreign Key
MNo{PK} char 10 not null
MDesc char 50 Not null
MLocation char 50 Not null
DEPENDENTS
Field Data Type Length Required Foreign Key
EID{PK} char 10 Not null EMPLOYEE
DeLastName char 20 Not null
DeFirstName char 20 Not null
DeMI char 4
DeGender char 1
DeBYear date
DeBMo date
DeBDay date
Relationship char 50
WorksOn
Field Data Type Length Required Foreign Key
EID{PK} char 10 Not null EMPLOYEE
PrNo char 10 Not null PROJECT
HoursPerMonth float

ProjectLocation
Field Data Type Length Required Foreign Key
PrNo{PK} char 10 Not null PROJECT
PrLocation char 50 Not null

FRIENDS
Field{PK} Data Type Length Required Foreign Key
EID1 char 10 Nut null EMPLOYEE
EID2 char 10 Nut null EMPLOYEE
USE
Field Data Type Length Required Foreign Key
EID{PK} char 10 Nut null EMPLOYEE
PrNo char 10 Nut null PROJECT
MNo char 10 Nut null MACHINE
UseDate date
SHour date
SMin date
EHour date
EMin date
HoursPerDay float

HasPhone
Field Data Type Length Required Foreign Key
EID{PK} char 10 Not null EMPLOYEE
EPhone char 10 Not null
Step by Step Conversion
From ERD to Tables
Tabular Representation of the
ER Diagram [EN2007]
STEP 1: For each regular (strong) entity type E in the
ER schema
• create a relation R that includes all the simple (and single
valued) attributes of E.
• include only the simple component attributes of a
composite attribute.
• choose one of the key attributes of E as primary key for
R.
• if the chosen key of E is composite, the set of simple
attributes that form it will together from the primary key of
R.
Step1- EDR To Relational: Strong Entity E
E

attribute-1{PK}
attribute-2
attribute-3
Primary Key attribute-3-a
attribute-3-b
attribute-4 [0..*]
/attribute-5

E
attribute-1 attribute-2 attribute-3-a attribute-3-b attribute-5

E(attribute-1, attribute-2, attribute-3-a, attribute-3-b, attribute-5)


friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* staff WorksFor
Friends
EID {PK} DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD EStNo MANAGES {R}

Controls
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate WorksOn
EBYear 1..*
EBMo 0..* 1..* PROJECT
EBDay
/EAge
DEPENDENTS 1..* 0..* PrNo {PK}
DeName PrName
USE {R}
JobIs

DeGender DeLastName PrLocation [1..*]


DeBDate DeFirstName
DeBYear UseDate
DeMI
DeBMo 0..1 Start Time
DeBDay 0..1 POSITION
SHour
MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Which are strong or weak entities? : Company
EMPLOYEE
POSITION PROJECT DEPENDENTS{W}
EID {PK}
EName PNo {PK} PrNo {PK} DeName {PK}
ELastName PName PrName DeLastName
EFirstName Salary PrLocation [1..*] DeFirstName
EMI DeMI
EAddress DeGender
EStNo Strong Entity DeBDate
EStName
Strong Entity DeBYear
ECity DeBMo
ECountry DeBDay
EPhone [0..3] DEPARTMENT MACHINE Relationship
EGender
EBDate DNo {PK} MNo {PK}
EBYear DName MDesc Weak Entity
EBMo DLocation MLocation
EBDay
/EAge

Strong Entity Strong Entity Strong Entity


Step-1 EDR To Relational: Strong Entity
EMPLOYEE
COMPANY
EID {PK}
EName
ELastName
EFirstName
EMI
EAddress
EStNo
EStName
ECity
ECountry
EPhone [0..3]
EGender
EBDate
EBYear
PK EBMo
EBDay
/EAge

EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName,


ECity, ECountry, EGender, EBYear, EBMo, EBDay, EAge)
Step-1 EDR To Relational: Strong Entity
COMPANY
POSITION
POSITION PNo PName Salary
PNo {PK}
PName
Salary
POSITION ( PNo, PName, Salary)

DEPARTMENT DEPARTMENT
DNo {PK} DNo DName DLocation
DName
DLocation

DEPARTMENT ( DNo, DName, DLocation)


Step-1 EDR To Relational: Strong Entity
COMPANY
PROJECT
PrNo PrName
PROJECT
PrNo {PK}
PrName
PrLocation [1..*]
PROJECT ( PrNo, PrName)

MACHINE
MACHINE MNo MDesc MLocation
MNo {PK}
MDesc
MLocation

MACHINE( MNo, MDesc, MLocation)


EDR To Relational: Company

After Step-1, we have the following relations:

EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName,


ECity, ECountry, EGender, EBYear, EBMo, EBDay, EAge)

POSITION ( PNo, PName, Salary)


DEPARTMENT ( DNo, DName, DLocation)
PROJECT ( PrNo, PrName)

MACHINE( MNo, MDesc, MLocation)


Tabular Representation of the
ER Diagram [EN2007]
STEP 2: For each weak entity type W in the ER schema with
owner entity type E,
• create a relation R and include all simple (and single valued)
attributes of W as attributes of R.
• include as foreign key attributes of R the primary key
attributes(s) of the relation(s) that correspond to the owner
entity type(s). This handles the identifying relationship type of
W.
• The primary key of R is the combination of the primary key(s)
of the owner(s) and the partial key of the weak entity type W,
if there are any.
Step2- EDR To Relational: Weak Entity W
E1 E2 {W}
attribute-a{PK} attribute-2
attribute-b attribute-3
attribute-c attribute-3-1
Foreign
attribute-1 attribute-3-2
Key
attribute-4 [0..*]
/attribute-5
Primary Key

W
attribute-a attribute-1 attribute-2 attribute-3-1 attribute-3-2 attribute-5

W(attribute-a, attribute-1, attribute-2, attribute-3-1, attribute-3-2, attribute-5)


Which are strong or weak entities? : Company
EMPLOYEE
POSITION PROJECT DEPENDENTS{W}
EID {PK}
EName PNo {PK} PrNo {PK} DeName {pk}
ELastName PName PrName DeLastName
EFirstName Salary PrLocation [1..*] DeFirstName
EMI DeMI
EAddress DeGender
EStNo Strong Entity DeBDate
EStName
Strong Entity DeBYear
ECity DeBMo
ECountry DeBDay
EPhone [0..3] DEPARTMENT MACHINE Relationship
EGender
EBDate DNo {PK} MNo {PK}
EBYear DName MDesc Weak Entity
EBMo DLocation MLocation
EBDay
/EAge

Strong Entity Strong Entity Strong Entity


Friends friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* EID {PK} staff WorksFor DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD MANAGES {R}

Controls
EStNo
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate
EBYear
WorksOn 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
PrNo {PK}
DeName 1.. 0..* PrName
DeGender USE {R}
JobI

DeLastName PrLocation [1..*]


DeBDate *
s

DeFirstName
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
EMPLOYEE
Step-1 EDR To Relational: Weak Entity
EID {PK}
EName DEPENDENTS{W}
ELastName
EFirstName DeGender
EMI DeBDate
EAddress DeBYear
EStNo DeBMo
EStName DeBDay COMPANY
ECity Relationship
ECountry
EPhone [0..3]
EGender
EBDate
EBYear
EBMo
EBDay
/EAge
DEPENDENTS ( EID, DeLastName, DeFirstName,
DeName DeMI, DeGender, DeBYear, DeBMo,
DeLastName
DeFirstName DeBday, Relationship)
DeMI

DEPENDENTS
EID DeLastName DeFirstName DeMI DeGender DeBYear DeBMo DeBDay Relationship
EDR To Relational:COMPANY

After Step-2, we have the following relations:

EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,


ECountry, EGender, EBYear, EBMo, EBDay, EAge)
POSITION ( PNo, PName, Salary)
DEPARTMENT ( DNo, DName, DLocation)
PROJECT ( PrNo, PrName)
MACHINE( MNo, MDesc, MLocation)
DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)
Tabular Representation of the
ER Diagram [EN2007]
STEP 3: For each binary 1:1 relationship type R in the
ER schema, identify the relations S and T that
correspond to the entity types participating in R.
• Choose an entity type with total participation (if there are any)
in R in the role of S; the other entity will play the role of T;
• Include as foreign key in S the primary key of T.
• Include all the simple (and single-valued) attributes of the
binary 1:1 relationship type R as attributes of S.

NOTE: For binary 1:1 relationship type:


• no new relation is created
• the entity that plays the role of S is modified
Step 3- EDR To Relational: Binary 1:1 CASE 1

E1 E2

attribute-a{PK} 1..1 0..1 attribute-1{PK}


attribute-b R attribute-2
attribute-c attribute-3
S T
Primary Key Foreign Key

E1
attribute- attribute-b attribute-c attribute-1
a

E1(attribute-a, attribute-b, attribute-c)


E1(attribute-a, attribute-b, attribute-c, attribute-1)
Step 3- EDR To Relational: Binary 1:1 CASE 2-A

E1 E2

attribute-a{PK} 1..1 1..1 attribute-1{PK}


attribute-b R attribute-2
attribute-c attribute-3
S T
Primary Key Foreign Key

E1
attribute- attribute-b attribute-c attribute-1
a

E1(attribute-a, attribute-b, attribute-c)


E1(attribute-a, attribute-b, attribute-c, attribute-1)
Step 3- EDR To Relational: Binary 1:1 CASE 2-B

E1 E2

attribute-a{PK} 1..1 1..1 attribute-1{PK}


attribute-b R attribute-2
attribute-c attribute-3

E1 E2
attribute- attribute-b attribute-c attribute- attribute-2 attribute-3
a 1
E1-E2
attribute-a attribute-b attribute-c attribute-1 attribute-2 attribute-3

E1-E2(attribute-a, attribute-b, attribute-c, attribute-1,attribute-2, attribute-3}


Step 3- EDR To Relational: Binary 1:1 CASE 3

E1 1..1 0..1 E2

attribute-a{PK} attribute-1{PK}
attribute-b attribute-2
attribute-c R attribute-3
attribute-r1
S attribute-r2 T
Primary Key Foreign Key

E1
attribute- attribute-b attribute-c attribute-1 attribute-r1 attribute-r2
a

E1(attribute-a, attribute-b, attribute-c)


E1(attribute-a, attribute-b, attribute-c, attribute-1, attribute-r1, attribute-r2)
Friends friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* EID {PK} staff WorksFor DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD MANAGES {R}

Controls
EStNo
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate
EBYear
WorksOn 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
PrNo {PK}
DeName 1.. 0..* PrName
DeGender USE {R}
JobI

DeLastName PrLocation [1..*]


DeBDate *
s

DeFirstName
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Step-3 EDR To Relational - Binary 1:1 Company
EMPLOYEE
EID {PK}
DEPARTMENT
EName
ELastName 0..1 1..1 DNo {PK}
EFirstName manager
DName S
DLocation
EMI
EAddress MANAGES {R}
EStNo
EStName MgrStartDate
ECity
ECountry DEPARTMENT
EPhone [0..3] T DNo DName DLocation MgrEID MgrStartDate
EGender
EBDate
EBYear DEPARTMENT ( DNo, DName, DLocation)
EBMo
EBDay
/EAge DEPARTMENT ( DNo, DName, Dlocation, MgrEID, MgrStartDate)
EDR To Relational:COMPANY

After Step-3, we have the following relations:

EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,


ECountry, EGender, EBYear, EBMo, EBDay, EAge)
POSITION ( PNo, PName, Salary)
DEPARTMENT ( DNo, DName, DLocation)
PROJECT ( PrNo, PrName)
MACHINE( MNo, MDesc, MLocation)
DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)

DEPARTMENT ( DNo, DName, Dlocation, MgrEID, MgrStartDate)


Tabular Representation of the
ER Diagram [EN2007]
STEP 4: For each regular (non-weak) binary 1:* (1:N)
relationship type R,
• identify the relation S that represents the participating entity
type at the N-side of the relationship type.
• Include as foreign key in S the primary key of the relation T
that represents the other entity type participating in R.
• Include any simple (and single-valued) attributes of the 1:N
relationship type as attributes of S.
Step 4- EDR To Relational: Binary 1:* Case 1
E1 E2

attribute-a{PK} 1..* 0..1 attribute-1{PK}


attribute-b R attribute-2
attribute-c attribute-3
S T
Primary Key Foreign Key

E1
attribute- attribute-b attribute-c attribute-1
a

E1(attribute-a, attribute-b, attribute-c)


E1(attribute-a, attribute-b, attribute-c, attribute-1)
Step 4- EDR To Relational: Binary 1:* CASE 2

E1 1..* 0..1 E2

attribute-a{PK} attribute-1{PK}
attribute-b attribute-2
attribute-c R attribute-3
attribute-r1
S attribute-r2 T
Primary Key Foreign Key

E1
attribute- attribute-b attribute-c attribute-1 attribute-r1 attribute-r2
a

E1(attribute-a, attribute-b, attribute-c)


E1(attribute-a, attribute-b, attribute-c, attribute-1, attribute-r1, attribute-r2)
Friends friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* EID {PK} staff WorksFor DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD MANAGES {R}

Controls
EStNo
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate
EBYear
WorksOn 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
PrNo {PK}
DeName 1.. 0..* PrName
USE {R}
JobIs

DeGender DeLastName PrLocation [1..*]


DeBDate DeFirstName *
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Step-4 EDR To Relational - Binary 1:* Company
EMPLOYEE 1..* 1..1 DEPARTMENT
staff WorksFor
EID {PK}
EName
ELastName
S T DNo {PK}
DName
DLocation
EFirstName
EMI
EAddress
0..1 T

Controls
EStNo
POSITION
EStName
ECity
1..* 0..1
PNo {PK}
ECountry
PName 1..*
EPhone [0..3] JobIs
EGender
EBDate S T Salary
PROJECT
S
EBYear PrNo {PK}
EBMo PrName
EBDay PrLocation [1..*]
/EAge Relations to be modified:
EMPLOYEE (EID, ELastName, EFirstName, EMI,
EStNo, EStName, ECity, ECountry, EGender, EBYear,
EBMo, EBDay, EAge)

PROJECT ( PrNo, PrName)


Step-4 EDR To Relational - Binary 1:* Company
EMPLOYEE 1..* 1..1 DEPARTMENT
EID {PK} staff WorksFor
DNo {PK}
EName
ELastName S T DName
DLocation
EFirstName
EMI
EAddress
EStNo
EStName 1..* 0..1 POSITION
ECity
PNo {PK}
ECountry JobIs PName
EPhone [0..3]
EGender
EBDate
S FK T
Salary

EBYear
EBMo EMPLOYEE (EID, ELastName, EFirstName,
EBDay PK EMI, EStNo, EStName, ECity, ECountry,
/EAge
EGender, EBYear, EBMo, EBDay, EAge)

EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo,


EStName, ECity, ECountry, EGender, EBYear, EBMo, EBDay,
EAge, DNo, PNo)
Step-4 EDR To Relational - Binary 1:* Company
DEPARTMENT
DNo {PK}
DName
DLocation

0..1
T
Controls

1..*
PROJECT
S
PrNo {PK}
PrName
PrLocation [1..*] PROJECT ( PrNo, PrName)

PROJECT ( PrNo, PrName, DNo)


EDR To Relational:COMPANY
After Step-4, we have the following relations:
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,
ECountry, EGender, EBYear, EBMo, EBDay, EAge)
POSITION ( PNo, PName, Salary)
PROJECT ( PrNo, PrName)

MACHINE( MNo, MDesc, MLocation)


DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)
DEPARTMENT ( DNo, DName, DLocation, MgrEID, MgrStartDate)
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,
ECountry, EGender, EBYear, EBMo, EBDay, EAge, DNo, PNo)
PROJECT ( PrNo, PrName, DNo)
Tabular Representation of the
ER Diagram [EN2007]
STEP 5: For each binary *:* (M:N) relationship type
R,
• create a new relation S to represent R.
• Include as foreign key attributes in S the primary keys
of the relations that represent the participating entity
types; their combination will form the primary key of
S.
• Also include any simple attributes of the M:N
relationship (or simple components of composite
attributes) as attributes of S.
Step 5- EDR To Relational: Binary *:* Case 1
E1 E2

attribute-a{PK} 1..* 0..* attribute-1{PK}


attribute-b R attribute-2
attribute-c attribute-3

Create a new relation

R
R(attribute-a, attribute-1)
attribute- attribute1
a

Primary Key
Foreign Key
Step 5- EDR To Relational: Binary *:*
Case 2
E1 E2
1..* 0..*
att-a{PK} att-1{PK}
att-b att-2
R
att-c att-3
att-r1
att-r2
Create a new relation

R
R(att-a, att-1, att-r1, att-r2)
att-a att-1 att-r1 att-r2

Foreign Key Primary Key


Friends friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* EID {PK} staff WorksFor DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD MANAGES {R}

Controls
EStNo
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate
EBYear
WorksOn 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
PrNo {PK}
DeName 1.. 0..* PrName
USE {R}
JobIs

DeGender DeLastName PrLocation [1..*]


DeBDate DeFirstName *
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Step-5 EDR To Relational - Binary *:* Company
WorksOn {R}
EMPLOYEE
friend1 0..*
HoursPerMonth
0..* EID {PK}
Friends

EName
ELastName 1..*
0..* EFirstName
PROJECT
EMI
friend2 EAddress
PrNo {PK}
PrName
EStNo
PrLocation [1..*]
EStName
ECity
ECountry
EPhone [0..3]
EGender New Relations To be Created:
EBDate
EBYear WorksOn
EBMo
EBDay
Friends
/EAge
Step-5 EDR To Relational - Binary *:* Company
WorksOn {R}
EMPLOYEE
0..*
HoursPerMonth
EID {PK}
EName
ELastName 1..*
EFirstName
PROJECT
EMI
PrNo {PK}
EAddress
PrName
EStNo
PrLocation [1..*]
EStName
ECity PK FK
ECountry
EPhone [0..3]
EGender
EBDate WorksOn
EBYear
EBMo EID PrNo HoursPerMonth
EBDay
/EAge

WorksOn ( EID, PrNo, HoursPerMonth )


Step-5 EDR To Relational - Binary *:* Company
EMPLOYEE
friend1
0..* EID {PK}
Friends

EName
ELastName
0..* EFirstName
EMI
friend2 EAddress
EStNo
EStName
ECity PK
ECountry
EPhone [0..3]
EGender
EBDate Friends
EBYear
EBMo EID1 EID2
EBDay
/EAge

Friends ( EID1, EID2)


EDR To Relational:COMPANY
After Step-5, we have the following relations:
POSITION ( PNo, PName, Salary)
MACHINE( MNo, MDesc, MLocation)
DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)
DEPARTMENT ( DNo, DName, DLocation, MgrEID, MgrStartDate)
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,
ECountry, EGender, EBYear, EBMo, EBDay, EAge, DNo, PNo)
PROJECT ( PrNo, PrName, DNo)
WorksOn ( EID, PrNo, HoursPerMonth )
FRIENDS ( EID1, EID2)
Tabular Representation of the
ER Diagram [EN2007]

STEP 6: For each multi-valued attribute A,


• create a new relation R that includes an attribute
corresponding to A.
• Include the primary key attribute K (as a foreign key
in R) of the relation that represents the entity type or
relationship type that has A as an attribute.
• The primary key of R is the combination of A and K.
If the multi-valued attribute is composite, include its
simple components.
Step 6- EDR To Relational: Binary Multi-valued
E1
Case1: multi-valued attribute
attribute-a{PK} is a simple attribute
attribute-b
attribute-c [1..*]

Create a new relation

R
R(attribute-a, attribute-1)
attribute- attribute1
a

Primary Key
Foreign Key
Step 6- EDR To Relational: Binary Multi-valued
E1
att-a{PK} Case2: multi-valued attribute
att-b is a composite attribute
att-c [1..*]
att-c-1 {pk}
att-c-2
att-c-3 discriminator
Create a new relation
R R(att-a, att-1, att-c-2 att-c-3)
att-a att-c-1 att-c-2 att-c-3

Primary Key
Foreign Key
Friends friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* EID {PK} staff WorksFor DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD MANAGES {R}

Controls
EStNo
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate
EBYear
WorksOn 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
PrNo {PK}
DeName 1.. 0..* PrName
USE {R}
JobIs

DeGender DeLastName PrLocation [1..*]


DeBDate DeFirstName *
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Step-6 EDR To Relational - Multi-valued Attribute
Create New Relations:
EMPLOYEE PROJECT HasPhone
EID {PK} ProjectLocation
EName PrNo {PK}
ELastName PrName
EFirstName PrLocation [1..*]
EMI
EAddress
EStNo
EStName HasPhone
ECity HasPhone ( EID, EPhone )
EID EPhone
ECountry
EPhone [0..3]
EGender
EBDate
EBYear Project Location
EBMo PrNo PrLocation
EBDay
/EAge

ProjectLocation ( PrNo, PrLocation )


EDR To Relational:COMPANY
After Step-6, we have the following relations:
POSITION ( PNo, PName, Salary)
MACHINE( MNo, MDesc, MLocation)
DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)
DEPARTMENT ( DNo, DName, DLocation, MgrEID, MgrStartDate)
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,
ECountry, EGender, EBYear, EBMo, EBDay, EAge, DNo, PNo)
PROJECT ( PrNo, PrName, DNo)
WorksOn ( EID, PrNo, HoursPerMonth )
FRIENDS ( EID1, EID2)
HasPhone ( EID, EPhone )
ProjectLocation ( PrNo, PrLocation )
Tabular Representation of the ER Diagram [EN2007]
STEP 7: For each n-ary relationship type R, n>2:
• create a new relation S to represent R.
• Include as foreign key attributes in S the primary keys of the
relations that represent the participating entity types.
• Also, include any simple attributes of the n-ary relationship
type (or simple components of composite attributes) as
attributes of S.
• The primary key of S is usually a combination of all the
foreign keys that reference the relations representing the
participating entity types.
• However if the cardinality constraints on any one of the entity
types E participating in R is1, then the primary key of S should
not include the foreign key attribute that references the
relation E’ corresponding to E.
Step 7- EDR To Relational: Multi-way (Cases)
E1 E2

attribute-a{PK} 0..* 1..* attribute-1{PK}


R
attribute-b attribute-2

0..*
E3

attribute-i{PK}
attribute-ii

Create a new relation S

S(attribute-a, attribute-1, attribute-i)


Step 7- EDR To Relational: Multi-way (Cases)
E1 R {R} E2

attribute-a{PK} 0..* attribute-r1


1..*
attribute-1{PK}
attribute-b attribute-r2 attribute-2

0..*
E3

attribute-i{PK}
PK attribute-ii

Create a new relation S

S(attribute-a, attribute-1, attribute-i, attribute-r1,attribute-r2)


Friends friend1 EMPLOYEE 1..* 1..1 DEPARTMENT
0..* EID {PK} staff WorksFor DNo {PK}
EName 0..1 1..1 DName
0..* ELastName
EFirstName manager DLocation
friend2 EMI 0..1
EAddress
ERD MANAGES {R}

Controls
EStNo
EStName
Company ECity MgrStartDate

Database ECountry WorksOn {R}


EPhone [0..3]
EGender
0..*
HoursPerMonth
EBDate
EBYear
WorksOn 1..*
EBMo 0..* 1..* PROJECT
EBDay
DEPENDENTS /EAge
PrNo {PK}
DeName 1.. 0..* PrName
USE {R}
JobIs

DeGender DeLastName PrLocation [1..*]


DeBDate DeFirstName *
DeBYear UseDate
DeMI
DeBMo Start Time
DeBDay 0..1 0..1 SHour
POSITION MACHINE
Relationship SMin
End Time
0..*
PNo {PK} EHour MNo {PK}
1..* Support PName
Salary
EMin
/HoursPerDay
MDesc
MLocation
Step-7 EDR To Relational - Multi-way: Company
EMPLOYEE
New Relation to be created:
EID {PK}
EName USE
ELastName
0..*
EFirstName
PROJECT
EMI
PrNo {PK}
EAddress 0..* PrName
EStNo USE {R} PrLocation [1..*]
EStName
ECity UseDate
ECountry Start Time
EPhone [0..3] SHour
EGender MACHINE
SMin
EBDate End Time
EBYear MNo {PK}
EHour
EBMo EMin 0..* MDesc
EBDay MLocation
/HoursPerDay
/EAge

USE
EID PrNo MNo UseDate SHour SMin EHour EMin HoursPerDay

USE ( EID, PrNo, Mno, UseDate, Shour, Smin, Ehour, Emin, HoursPerDay )
EDR To Relational:COMPANY
After Step-7, we have the following relations:
POSITION ( PNo, PName, Salary)
MACHINE( MNo, MDesc, MLocation)
DEPENDENTS ( EID, DeLastName, DeFirstName, DeMI, DeGender,
DeBYear, DeBMo, DeBDay, Relationship)
DEPARTMENT ( DNo, DName, DLocation, MgrEID, MgrStartDate)
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName, ECity,
ECountry, EGender, EBYear, EBMo, EBDay, EAge, DNo, PNo)
PROJECT ( PrNo, PrName, DNo)
WorksOn ( EID, PrNo, HoursPerMonth )
FRIENDS ( EID, EID2)
HasPhone ( EID, EPhone )
ProjectLocation ( PrNo, PrLocation )
USE ( EID, PrNo, Mno, UseDate, SHour, SMin, EHour, EMin, HoursPerDay )
EMPLOYEE
Field Data Type Length Required Foreign Key
EID char 10 Not null
ELastName char 30 Not null
EFirstName char 30 Not null
EMI char 4
EStNo char 5
EStName char 20
ECity char 20 Not null
ECountry char 20 Not null
EGender char 1 Not null
EBYear Date Not null
EBMo Date Not null
EBDay Date Not null
EAge int
DNo char 5 Not null DEPARTMENT
PNo char 5 Not null POSITION
DEPARTMENT
Field Data Type Length Required Foreign Key
DNo char 10 Not null
DName char 50 Not null
DLocation char 50 Not null
MgrEID char 10 EMPLOYEE
MgrStartDate Date

POSITION
Field Data Type Length Required Foreign Key
PNo char 10 Not null
PName char 50 Not null
Salary money
PROJECT
Field Data Type Length Required Foreign Key
PrNo char 10 Not null
PrName char 50 Not null
DNo char 10 Not null DEPARTMENT

MACHINE
Field Data Type Length Required Foreign Key
MNo char 10 not null
MDesc char 50 Not null
MLocation char 50 Not null
DEPENDENTS
Field Data Type Length Required Foreign Key
EID char 10 Not null EMPLOYEE
DeLastName char 20 Not null
DeFirstName char 20 Not null
DeMI char 4
DeGender char 1
DeBYear date
DeBMo date
DeBDay date
Relationship char 50
WorksOn
Field Data Type Length Required Foreign Key
EID char 10 Not null EMPLOYEE
PrNo char 10 Not null PROJECT
HoursPerMonth float

ProjectLocation
Field Data Type Length Required Foreign Key
PrNo char 10 Not null PROJECT
PrLocation char 50 Not null

FRIENDS
Field Data Type Length Required Foreign Key
EID1 char 10 Nut null EMPLOYEE
EID2 char 10 Nut null EMPLOYEE
USE
Field Data Type Length Required Foreign Key
EID char 10 Nut null EMPLOYEE
PrNo char 10 Nut null PROJECT
MNo char 10 Nut null MACHINE
UseDate date
SHour date
SMin date
EHour date
EMin date
HoursPerDay float

HasPhone
Field Data Type Length Required Foreign Key
EID char 10 Not null EMPLOYEE
EPhone char 10 Not null
Exercises
Exercise #1 : Reduce to Relations (Tables)
STUDENT

SID {PK}
SName
SDegree
SGPA

1..*

FACULTY COURSE
ENROLL {R}
0..* 1..*
FID {PK} CCode {PK}
Section
FName CName
RoomNo
FDegree CDesc
Sked
DNo CUnits
Day
StartTime
EndTime
Grade
Exercise #2 : Reduce to Relations (Tables)
COURSE
STUDENT
CCode {PK}
SID {PK} CName
SName CDesc
SDegree CUnits
SGPA Sec {PK}

1..* 0..1

Offering
1..*
FACULTY 0..* ENROLL {R}
1..* CLASS {W}
FID {PK} Grade Sec {PK}
FName
RoomNo
FDegree
Sked
DNo
Day
StartTime
EndTime
Exercise #3 : Reduce to Relations (Tables)

No partial key
PROJECT
SUPPLIER
SUPPLY {W}
1..* 0..1 ProjName {PK}
SName {PK} 1..*
Quantity ProjDesc
SAddress
ProjLeader
1..*
S-Part
0..1
0..1
S-S PART S-Proj
HOW?? PartNo {PK}
Convert the PartDesc
relationship supply to a
weak entity
Exercise #4 : Reduce to Relations (Tables)

SUPPLY PROJECT
SUPPLIER

0..1 1..* SupplyNo {PK} ProjName {PK}


SName {PK} 1..* 0..1
Quantity ProjDesc
SAddress S-S S-Proj ProjLeader
1..*
S-Part

HOW?? 0..1 Primary Key


Convert the relationship PART (surrogate key)
supply to a Strong entity
and add an artificial or PartNo {PK}
surrogate key PartDesc
Exercise #5 : Reduce to Relations (Tables) LOAN-TRAN {W}
BANK BRANCH {W} LT-Date
1..*
BkCode {PK} LT-Type
BkHasBr
BkName LT-Amount
BrAddress
BkAddress 1..*
0..1 0..1
BrNo 1..1

Do-LT
Br-Offer-Acct

Br-Offer-Acct
LOAN
ACCOUNT LoanNo {PK}
1..*
ACCT-TRAN AcctNo {PK} Amount
{W} 1..*
Balance LoanType
AT-Date CUSTOME
AcctType R LT-No
AT-Type 1..*
AT-No 1..* SSN {PK} Cust-Loan
AT-Amount 1..1
1..1 CName
Cust-Acct
CAddress 0..*
1..* Do-AT 0..* CPhone
Exercise #6 : Reduce to Relations (Tables)
0 ..*
C F
1..* 0..* A B 0..*
c1{PK} f1{PK} 1..1 1..1
a1{PK} b1{PK}
c2 f2
R10 b2
c3 [1..*] a2
f3 b3 R2{R}
c4 {d/pk} a3 R1{R}
f4 r2-1 [1..*]
c5 1..* r1-1 e1
1..1
r2-2 {d}
c6 r1-2 0..1
R6 r2-3
0..1 1..*
r2-4
R4{R} I E {W}
R5 r4-1 i1 {PK} e2
0..* i2 /e3
r4-2
1..1
0..1 1..1
D R8
1..1 1..* 1..*
d1{PK}
J H {W} R7 G R3{R}
d2 R9
j1{PK} h1 g1{PK} r3-1
d3 1..* 1..*
j2 0..1 h2 0..1 g2 r3-2
d4
END … Thank You!!

75
MS ACCESS DATA TYPES
Data type Storage size Description
Any type of data may be stored
in a field of this type. No
translation of the data (for
1 byte per
BINARY example, to text) is made. How
character
the data is input in a binary
field dictates how it will appear
as output.
Yes and No values and fields
BIT 1 byte that contain only one of two
values.
An integer value between 0 and
TINYINT 1 byte
255.
MS ACCESS DATA TYPES
Data type Storage Size Description
A scaled integer
between
– 922,337,203,685,477
MONEY 8 bytes
.5808 and
922,337,203,685,477.5
807.
A date or time value
DATE 8 bytes between the years 100
and 9999.
A unique identification
UNIQUEIDENTIFIER 128 bits number used with
remote procedure calls.
MS ACCESS DATA TYPES
Data type Storage size Description
A single-precision floating-point value
with a range of – 3.402823E38 to
REAL 4 bytes – 1.401298E-45 for negative values,
1.401298E-45 to 3.402823E38 for positive
values, and 0.
A double-precision floating-point value
with a range of – 1.79769313486232E308
to – 4.94065645841247E-324 for negative
FLOAT 8 bytes values, 4.94065645841247E-324 to
1.79769313486232E308 for positive
values, and 0.
A short integer between – 32,768 and
SMALLINT 2 bytes 32,767. (See Notes)
Data type Storage size Description
A long integer between – 2,147,483,648
INTEGER 4 bytes and 2,147,483,647. (See Notes)
An exact numeric data type that holds
values from 1028 - 1 through - 1028 - 1.
You can define both precision (1 - 28)
DECIMAL 17 bytes and scale (0 - defined precision). The
default precision and scale are 18 and 0,
respectively.
2 bytes per
TEXT Zero to a maximum of 2.14 gigabytes.
character
Zero to a maximum of 2.14 gigabytes.
IMAGE As required Used for OLE objects.
2 bytes per
CHARACTER Zero to 255 characters.
character
Source Type Target Type
Java Pre-Type Java Type Java Post-Type Data Element Type
boolean bit
byte tiny integer
short small integer
int integer
long long binary
float float
double double precision
const char character
char character varying
const char * long character
char * long text
char * long var character
default long var character
Step 7- EDR To Relational: Multi-way
E1 E2

attribute-a{PK} 0..* 1..* attribute-1{PK}


R
attribute-b attribute-2

Case 1: 0..*
• Cardinality -All Many E3
• R has no attributes
attribute-i{PK}
attribute-ii

Create a new relation S

S(attribute-a, attribute-1, attribute-i)


Step 7- EDR To Relational: Multi-way
E1 E2

attribute-a{PK} 0..* 1..* attribute-1{PK}


R
attribute-b attribute-2

0..1
Case 2:
E3
• Mixture of many
and one cardinalities Do not include
attribute-i{PK} in the primary
• R has no attributes
attribute-ii key (whose
cardinality is
Create a new relation S one); but
include as a
S(attribute-a, attribute-1, attribute-i) foreign key
Step 7- EDR To Relational: Multi-way
E1 E2

attribute-a{PK} 0..1 1..1 attribute-1{PK}


R
attribute-b attribute-2

0..1
Case 3:
E3
• All one cardinalities
• Mixture of total and
attribute-i{PK}
partial
attribute-ii Foreign key
• R has no attributes

Modify relation E2 (with total participation)


E2(attribute-1, attribute-2, attribute-a, attribute-i)
Step 7- EDR To Relational: Multi-way
E1 E2

attribute-a{PK} 1..1 1..1 attribute-1{PK}


R
attribute-b attribute-2

1..1
Case 4-a:
E3
• All one cardinalities
• All total
attribute-i{PK}
participation
attribute-ii Foreign key
• R has no attributes

Modify relation E1, E2 or E3 (with total participation)


E1(attribute-a, attribute-b, attribute-1, attribute-i)
Step 7- EDR To Relational: Multi-way
E1 E2

attribute-a{PK} 1..1 1..1 attribute-1{PK}


R
attribute-b attribute-2

1..1
Case 4-b:
E3
• All one cardinalities
• All total
attribute-i{PK}
participation
attribute-ii
• R has no attributes
Drop relations E1, E2 and E3 and then create a new relation S
S(attribute-a, attribute-b, attribute-1, attribute-2, attribute-i,
attribute-ii)
Step 7- EDR To Relational: Multi-way
E1 R {R} E2

attribute-a{PK} 0..* attribute-r1


1..*
attribute-1{PK}
attribute-b attribute-r2 attribute-2

Case 5: 0..*
• Cardinality -All Many E3
• R has attributes
attribute-i{PK}
attribute-ii

Create a new relation S

S(attribute-a, attribute-1, attribute-i, attribute-r1,attribute-r2)


Step 7- EDR To Relational: Multi-way
E1 R {R} E2

attribute-a{PK} 0..* attribute-r1


1..*
attribute-1{PK}
attribute-b attribute-r2 attribute-2

0..1 Do not include


Case 6:
E3 in the primary
• Mixture of many
and one cardinalities key (whose
attribute-i{PK} cardinality is
• R has attributes
attribute-ii one); but
include as
Create a new relation S foreign key

S(attribute-a, attribute-1, attribute-i, attribute-r1,attribute-r2)


Step 7- EDR To Relational: Multi-way
E1 R {R} E2

attribute-a{PK} 1..1 attribute-r1


1..1
attribute-1{PK}
attribute-b attribute-r2 attribute-2

Case 7: 0..1
• All one cardinalities E3
• Mixture of total and
partial attribute-i{PK}
• R has attributes attribute-ii Foreign key

Modify either E1 or E2 (with total participation)

E1(attribute-a, attribute-b, attribute-1,attribute-i,


attribute-r1,attribute-r2)
Step 7- EDR To Relational: Multi-way
E1 R {R} E2

attribute-a{PK} 1..1 attribute-r1


1..1
attribute-1{PK}
attribute-b attribute-r2 attribute-2

Case 8-a: 1..1


• All one cardinalities E3
• All total
participation attribute-i{PK} Foreign key
• R has attributes attribute-ii
Modify any of relations E1, E2 and E3 (total participation)
E1(attribute-a, attribute-b, attribute-1, attribute-i,
attribute-r1,attribute-r2)
Step 7- EDR To Relational: Multi-way
E1 R {R} E2

attribute-a{PK} 1..1 attribute-r1


1..1
attribute-1{PK}
attribute-b attribute-r2 attribute-2

Case 8-b: 1..1


• All one cardinalities E3
• All total
participation attribute-i{PK} Foreign
• R has attributes attribute-ii key

Drop relations E1, E2 and E3 and then create a new relation S


S(attribute-a, attribute-b, attribute-1, attribute-2, attribute-i,
attribute-ii, attribute-r1,attribute-r2)
Attribute Types: Required Vs Optional
• Required Attribute - its value must be supplied
by the user. It cannot be left blank (not null).
Example: IDNo
Position
• Optional Attribute - a field that may be left
blank because:
– the information may exist but is not currently
known, or
– because the field doesn't apply to the record at all.
Example: Phone No
skills
professional exams
Convert the ERD into Relational Schema
d3 d4
a1 a2 a3 b1 b2 b3
M
d1 d2 1 1
R R
A 1
B
3
D N r1 1 N
R R r3
M
r5 M 2 4
R r2
N e1 e2
6
N
N R C
5 N
F 1 E
r4 c1 C2 C3
f1 f2

C4 C5 C6
f3 f4

Вам также может понравиться