lecture 03 erd to relational
TRANSCRIPT
-
8/8/2019 Lecture 03 ERD to Relational
1/92
Reducing E-R Diagrams to
Tables
Remedios de Dios Bulos
-
8/8/2019 Lecture 03 ERD to Relational
2/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstName
EMIEAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..* 1..10..*
0..*
friend1
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}
PNameSalary
J
obI
s
1..*
0..1
1..10..1
Co
ntro
ls
0..1
1..*
MACHINE
MNo {PK}MDescMLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeName
DeLastNameDeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
-
8/8/2019 Lecture 03 ERD to Relational
3/92
Objective : Logical Design
Design Relational Schema of a Company
-
8/8/2019 Lecture 03 ERD to Relational
4/92
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 )
HasPhone (EID, EPhone )
ProjectLocation (PrNo, PrLocation )
USE ( EID,PrNo,MNo, UseDate, SHour, SMin, EHour, EMin, HoursPerDay )
Friends (EID1,EID2)
-
8/8/2019 Lecture 03 ERD to Relational
5/92
EMPLOYEE
Field DataType
LengthRequired
Foreign Key
EID {PK} char 10 Not nullELastName
char 30 Not nullEFirstName char 30 Not nullEMI :PK char 4EStNo char 5EStName char 20ECity char 20 Not nullECountry char 20 Not nullEGender char 1 Not nullEBYear Date Not null
EBMo Date Not nullEBDay Date Not nullEAge intDNo char 5 Not null DEPARTME
NTPNochar 5
Not null POSITION
-
8/8/2019 Lecture 03 ERD to Relational
6/92
DEPARTMENT
Field DataType
LengthRequired
Foreign Key
DNo {PK} char 10 Not nullDName char 50 Not nullDLocation char 50 Not nullMgrEID char 10 EMPLOYEEMgrStartDate Date
POSITION
Field Data
Type
LengthRequire
d
Foreign Key
PNo{PK} char 10 Not nullPName char 50 Not nullSalary money
-
8/8/2019 Lecture 03 ERD to Relational
7/92
PROJECT
Field DataType
LengthRequired
Foreign Key
PrNo{PK} char 10 Not null
PrName char 50 Not nullDNo char 10 Not null DEPARTME
NTMACHINE
Field Data
Type
LengthRequire
d
Foreign Key
MNo{PK} char 10 not nullMDesc char 50 Not nullMLocation char 50 Not null
-
8/8/2019 Lecture 03 ERD to Relational
8/92
DEPENDENTS
Field Data
Type
LengthRequire
d
Foreign Key
EID{PK} char 10 Not null EMPLOYEEDeLastName char 20 Not nullDeFirstName char 20 Not nullDeMI char 4DeGender char 1DeBYear dateDeBMo dateDeBDay dateRelationship char 50
-
8/8/2019 Lecture 03 ERD to Relational
9/92
WorksOn
Field DataType
LengthRequired
Foreign Key
EID{PK} char 10 Not null EMPLOYEE
PrNo char 10 Not null PROJECTHoursPerMonth float
ProjectLocation
Field DataType LengthRequired Foreign KeyPrNo{PK} char 10 Not null PROJECTPrLocation char 50 Not null
FRIENDS
Field{PK}DataType
LengthRequired
Foreign KeyEID1 char 10 Nut null EMPLOYEEEID2 char 10 Nut null EMPLOYEE
-
8/8/2019 Lecture 03 ERD to Relational
10/92
USE
Field DataType
LengthRequired
Foreign Key
EID{PK} char 10 Nut null EMPLOYEEPrNo
char 10 Nut null PROJECTMNo char 10 Nut null MACHINEUseDate dateSHour dateSMin dateEHour dateEMin dateHoursPerDay float
HasPhone
Field DataType
LengthRequired
Foreign Key
EID{PK} char 10 Not null EMPLOYEEEPhone char 10 Not null
-
8/8/2019 Lecture 03 ERD to Relational
11/92
Step by Step Conversion
From ERD to Tables
-
8/8/2019 Lecture 03 ERD to Relational
12/92
Tabular Representation of theER Diagram [EN2007]
STEP 1: For each regular (strong) entity type E in theER schema
create a relation R that includes all thesimple (and singlevalued) attributes of E.
include only the simple component attributes of acomposite attribute.
choose one of the key attributes of E as primary key forR.
if the chosen key of E is composite, the set of simpleattributes that form it will together from the primary keyof R.
-
8/8/2019 Lecture 03 ERD to Relational
13/92
E(attribute-1, attribute-2, attribute-3-a, attribute-3-b, attribute-
5)
Step1- EDR To Relational: Strong Entity E
E
attribute-1{PK}attribute-2attribute-3
attribute-3-a
attribute-3-battribute-4 [0..*]/attribute-5
E
attribute-1
attribute-2
attribute-3-a
attribute-3-b
attribute-5
Primary
Key
-
8/8/2019 Lecture 03 ERD to Relational
14/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..* 1..10..*
0..*
friend1
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PNameSalary
J
obIs
1..*
0..1
1..10..1
Co
ntro
ls
0..1
1..*
MACHINE
MNo {PK}MDesc
MLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeNameDeLastNameDeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
-
8/8/2019 Lecture 03 ERD to Relational
15/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNo
EStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DName
DLocation
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PNameSalary
MACHINE
MNo {PK}MDesc
MLocation
DEPENDENTS{W}
DeName {PK}DeLastNameDeFirstNameDeMI
DeGenderDeBDate
DeBYearDeBMoDeBDay
Relationship
Strong Entity
Strong Entity
Strong EntityStrong Entity
Strong Entity
Weak Entity
Which are strong or weak entities? : Company
-
8/8/2019 Lecture 03 ERD to Relational
16/92
Step-1 EDR To Relational: Strong Entity
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECity
ECountryEPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
EMPLOYEE (EID, ELastName, EFirstName, EMI, EStNo, EStName,ECity, ECountry, EGender, EBYear, EBMo, EBDay, EAge)
COMPANY
PK
-
8/8/2019 Lecture 03 ERD to Relational
17/92
Step-1 EDR To Relational: Strong Entity
COMPANY
DEPARTMENT
DNo {PK}DName
DLocation
POSITION
PNo {PK}PNameSalary
POSITION
PNo PNameSalary
POSITION (PNo, PName, Salary)
DEPARTMENT
DNo DNam
e
DLocatio
n
DEPARTMENT (DNo, DName, DLocation)
-
8/8/2019 Lecture 03 ERD to Relational
18/92
Step-1 EDR To Relational: Strong Entity
COMPANY
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
MACHINE
MNo {PK}MDescMLocation
PROJECT
PrNo PrName
PROJECT (PrNo, PrName)
MACHINE
MNo MDescMLocatio
n
MACHINE(MNo, MDesc, MLocation)
-
8/8/2019 Lecture 03 ERD to Relational
19/92
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)
-
8/8/2019 Lecture 03 ERD to Relational
20/92
STEP 2: For each weak entity type Win the ER schema withowner entity type E,
create a relation R and include allsimple (and single valued)attributes of W as attributes of R.
include as foreign key attributesofR theprimary keyattributes(s) of the relation(s) that correspond to the ownerentity type(s). This handles the identifying relationship typeof W.
Theprimary key of R is the combination of theprimary key(s)of the owner(s) and thepartial key of the weak entity typeW, if there are any.
Tabular Representation of theER Diagram [EN2007]
-
8/8/2019 Lecture 03 ERD to Relational
21/92
W(attribute-a, attribute-1, attribute-2, attribute-3-1, attribute-3-2, attribute-
5)
Step2- EDR To Relational: Weak Entity W
E2 {W}attribute-2
attribute-3attribute-3-1attribute-3-2
attribute-4 [0..*]
/attribute-5
W
attribute-1
attribute-2
attribute-3-1
attribute-3-2
attribute-5
PrimaryKey
E1attribute-a{PK}
attribute-battribute-c
attribute-a
ForeignKey
attribute-1
-
8/8/2019 Lecture 03 ERD to Relational
22/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNo
EStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DName
DLocation
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PNameSalary
MACHINE
MNo {PK}MDesc
MLocation
DEPENDENTS{W}
DeName {pk}DeLastNameDeFirstNameDeMI
DeGenderDeBDate
DeBYearDeBMoDeBDay
Relationship
Strong Entity
Strong Entity
Strong EntityStrong Entity
Strong Entity
Weak Entity
Which are strong or weak entities? : Company
-
8/8/2019 Lecture 03 ERD to Relational
23/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..* 1..10..*
0..*
friend1
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PNameSalary
Job
Is
1..
*
0..1
1..10..1
Co
ntr
ols
0..1
1..*
MACHINE
MNo {PK}MDesc
MLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeNameDeLastNameDeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
-
8/8/2019 Lecture 03 ERD to Relational
24/92
Step-1 EDR To Relational: Weak Entity
COMPANY
DEPENDENTS (EID,DeLastName,DeFirstName,DeMI, DeGender, DeBYear, DeBMo,
DeBday, Relationship)
DEPENDENTS{W}
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
DEPENDENTSDeLastName DeFirstName DeMI DeGender DeBYear DeBMo DeBDay Relationship
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
EID
DeNameDeLastNameDeFirstNameDeMI
-
8/8/2019 Lecture 03 ERD to Relational
25/92
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)
-
8/8/2019 Lecture 03 ERD to Relational
26/92
STEP 3: For each binary 1:1 relationship type R in theER schema, identify the relationsS and Tthatcorrespond to the entity typesparticipating 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 asforeign key in Stheprimary key of T.
Include all the simple (and single-valued) attributes of thebinary 1:1 relationship type R as attributes of S.
Tabular Representation of theER Diagram [EN2007]
NOTE: For binary 1:1 relationship type:no new relation is createdthe entity that plays the role of S is modified
-
8/8/2019 Lecture 03 ERD to Relational
27/92
E1(attribute-a, attribute-b, attribute-c, attribute-1)
Step 3- EDR To Relational: Binary 1:1
E2
attribute-1{PK}attribute-2attribute-3
E1
attribute-a attribute-b attribute-c
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c
1..1 0..1
R
ST Foreign
Key
attribute-1
E1(attribute-a, attribute-b, attribute-c)
CASE 1
-
8/8/2019 Lecture 03 ERD to Relational
28/92
E1(attribute-a, attribute-b, attribute-c, attribute-1)
Step 3- EDR To Relational: Binary 1:1
E2
attribute-1{PK}attribute-2attribute-3
E1
attribute-a attribute-b attribute-c
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c
1..1 1..1
R
ST Foreign
Key
attribute-1
E1(attribute-a, attribute-b, attribute-c)
CASE 2-A
-
8/8/2019 Lecture 03 ERD to Relational
29/92
E1-E2(attribute-a, attribute-b, attribute-c, attribute-1,attribute-2, attribute-
3}
Step 3- EDR To Relational: Binary 1:1
E2
attribute-1{PK}attribute-2attribute-3
E2
attribute-1 attribute-2 attribute-3
E1
attribute-a{PK}attribute-battribute-c
1..1 1..1
R
CASE 2-B
E1
attribute-a attribute-b attribute-c
E1-E2attribute-a attribute-b attribute-c attribute-1 attribute-2 attribute-3
-
8/8/2019 Lecture 03 ERD to Relational
30/92
E1(attribute-a, attribute-b, attribute-c, attribute-1, attribute-r1, attribute-r2)
Step 3- EDR To Relational: Binary 1:1
E2
attribute-1{PK}attribute-2attribute-3
E1
attribute-a attribute-b attribute-c
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c
1..1 0..1
ST Foreign
Key
attribute-1 attribute-r1 attribute-r2
E1(attribute-a, attribute-b, attribute-c)
Rattribute-r1
attribute-r2
CASE 3
EMPLOYEE 1 *f i d1
-
8/8/2019 Lecture 03 ERD to Relational
31/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..* 1..10..*
0..*
friend1
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PName
Salary
Job
Is
1..
*
0..1
1..10..1
Co
ntr
ols
0..1
1..*
MACHINE
MNo {PK}MDesc
MLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeNameDeLastNameDeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
-
8/8/2019 Lecture 03 ERD to Relational
32/92
EMPLOYEEEID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNo
EStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
Step-3 EDR To Relational - Binary 1:1 Company
1..10..1
MANAGES {R}
MgrStartDate
managerS
TDEPARTMENTDNo DNam
eDLocation
DEPARTMENT (DNo, DName, DLocation)
MgrEIDMgrStartDate
DEPARTMENT (DNo, DName, Dlocation, MgrEID, MgrStartDate)
-
8/8/2019 Lecture 03 ERD to Relational
33/92
-
8/8/2019 Lecture 03 ERD to Relational
34/92
STEP 4: For each regular (non-weak) binary 1:* (1:N)relationship type R,
identify the relation S that represents the participating entitytype at the N-side of the relationship type.
Include as foreign key in S the primary key of the relation Tthat represents the other entity type participating in R.
Include any simple (and single-valued) attributes of the 1:Nrelationship type as attributes of S.
Tabular Representation of theER Diagram [EN2007]
-
8/8/2019 Lecture 03 ERD to Relational
35/92
E1(attribute-a, attribute-b, attribute-c, attribute-1)
Step 4- EDR To Relational: Binary 1:*
E2
attribute-1{PK}attribute-2attribute-3
E1
attribute-a attribute-b attribute-c
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c
1..* 0..1
R
ST Foreign
Key
attribute-1
E1(attribute-a, attribute-b, attribute-c)
Case 1
-
8/8/2019 Lecture 03 ERD to Relational
36/92
E1(attribute-a, attribute-b, attribute-c, attribute-1, attribute-r1, attribute-r2)
Step 4- EDR To Relational: Binary 1:*
E2
attribute-1{PK}attribute-2attribute-3
E1
attribute-a attribute-b attribute-c
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c
1..* 0..1
ST Foreign
Key
attribute-1 attribute-r1 attribute-r2
E1(attribute-a, attribute-b, attribute-c)
Rattribute-r1
attribute-r2
CASE 2
EMPLOYEE 1 * 1 1friend1
-
8/8/2019 Lecture 03 ERD to Relational
37/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..* 1..10..*
0..*
friend1
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PName
Salary
JobIs
1..
*
0..1
1..10..1
Co
ntr
ols
0..1
1..*
MACHINE
MNo {PK}MDesc
MLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeNameDeLastName
DeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
St 4 EDR T R l ti l Bi 1 * C
-
8/8/2019 Lecture 03 ERD to Relational
38/92
EMPLOYEE
EID {PK}
ENameELastNameEFirstNameEMI
EAddressEStNoEStNameECity
ECountryEPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..* 1..1
WorksFor
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PNameSalaryJobIs
1..* 0..1
Co
ntr
ols
0..1
1..*
staff
S T
S
T
TS
EMPLOYEE (EID, ELastName, EFirstName, EMI,EStNo, EStName, ECity, ECountry, EGender, EBYear,EBMo, EBDay, EAge)
PROJECT (PrNo, PrName)
Relations to be modified:
Step-4 EDR To Relational - Binary 1:* Company
St 4 EDR T R l ti l Bi 1 * C
-
8/8/2019 Lecture 03 ERD to Relational
39/92
EMPLOYEE
EID {PK}
ENameELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}
DNameDLocation
1..* 1..1
WorksFor
POSITION
PNo {PK}PNameSalary
JobIs
1..* 0..1
staff
S T
TS
EMPLOYEE (EID, ELastName, EFirstName,EMI, EStNo, EStName, ECity, ECountry,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
PK
FK
St 4 EDR T R l ti l Bi 1 * C
-
8/8/2019 Lecture 03 ERD to Relational
40/92
DEPARTMENT
DNo {PK}DNameDLocation
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
Co
ntr
ols
0..1
1..*
S
T
PROJECT (PrNo, PrName)
PROJECT (PrNo, PrName, DNo)
Step-4 EDR To Relational - Binary 1:* Company
EDR T R l ti l COMPANY
-
8/8/2019 Lecture 03 ERD to Relational
41/92
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)
-
8/8/2019 Lecture 03 ERD to Relational
42/92
STEP 5: For each binary *:* (M:N) relationshiptype R,
create a new relation Sto represent R.
Include as foreign key attributes in S the primary keysof the relations that represent the participatingentity types; their combination will form the
primary key of S.
Also include any simple attributes of the M:Nrelationship (or simple components of compositeattributes) as attributes of S.
Tabular Representation of theER Diagram [EN2007]
-
8/8/2019 Lecture 03 ERD to Relational
43/92
R(attribute-a, attribute-1)
Step 5- EDR To Relational: Binary *:*
E2
attribute-1{PK}attribute-2attribute-3
R
attribute-a attribute1
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c
1..* 0..*
R
ForeignKey
Case 1
Create a new relation
Step 5- EDR To Relational: Binary *:*
-
8/8/2019 Lecture 03 ERD to Relational
44/92
R(att-a, att-1, att-r1, att-r2)
Step 5 EDR To Relational: Binary :
E2
att-1{PK}att-2att-3
R
att-a att-1 att-r1 att-r2
PrimaryKey
E1
att-a{PK}att-batt-c
1..* 0..*
ForeignKey
Case 2
Create a new relation
Ratt-r1att-r2
EMPLOYEE DEPARTMENT1 * 1 1friend1
-
8/8/2019 Lecture 03 ERD to Relational
45/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1.. 1..10..*
0..*
friend1
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PName
Salary
Jo
bIs
1..
*
0..1
1..10..1
Co
ntr
ols
0..1
1..*
MACHINE
MNo {PK}MDesc
MLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeNameDeLastName
DeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
Step 5 EDR To Relational Binary *:* Company
-
8/8/2019 Lecture 03 ERD to Relational
46/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
0..*
0..*
friend1
friend2
Fr
ien
ds
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
WorksOn {R}
HoursPerMonth0..*
1..*
Step-5 EDR To Relational - Binary *:* Company
New Relations To be Created:WorksOnFriends
-
8/8/2019 Lecture 03 ERD to Relational
47/92
Step 5 EDR To Relational Binary *:* Company
-
8/8/2019 Lecture 03 ERD to Relational
48/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
0..*
0..*
friend1
friend2
Fr
ien
ds
Step-5 EDR To Relational - Binary *:* Company
Friends (EID1,EID2)
Friends
EID1 EID2
PK
EDR To Relational:COMPANY
-
8/8/2019 Lecture 03 ERD to Relational
49/92
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)
-
8/8/2019 Lecture 03 ERD to Relational
50/92
STEP 6: For each multi-valued attribute A,
create a new relation Rthat includes an attributecorresponding to A.
Include the primary key attribute K (as a foreign keyin R) of the relation that represents the entity typeor 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, includeits simple components.
Tabular Representation of theER Diagram [EN2007]
St 6 EDR T R l ti l Bi M lti l d
-
8/8/2019 Lecture 03 ERD to Relational
51/92
R(attribute-a, attribute-1)
Step 6- EDR To Relational: Binary Multi-valued
R
attribute-a attribute1
PrimaryKey
E1
attribute-a{PK}attribute-battribute-c [1..*]
ForeignKey
Create a new relation
Case1: multi-valued attributeis a simple attribute
St 6 EDR T R l ti l Bi M lti l d
-
8/8/2019 Lecture 03 ERD to Relational
52/92
R(att-a, att-1, att-c-2 att-c-3)
Step 6- EDR To Relational: Binary Multi-valued
R
att-a att-c-1 att-c-2 att-c-3
PrimaryKey
E1att-a{PK}
att-batt-c [1..*]
att-c-1 {pk}att-c-2
att-c-3
ForeignKey
Create a new relation
Case2: multi-valued attributeis a composite attribute
discriminator
EMPLOYEE DEPARTMENT1..* 1..1friend1
-
8/8/2019 Lecture 03 ERD to Relational
53/92
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
DEPARTMENT
DNo {PK}DNameDLocation
1..10..*
0..*
friend2
WorksFor
Fr
ien
ds
0..1
1..* Support
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
POSITION
PNo {PK}PName
Salary
Jo
bIs
1..
*
0..1
1..10..1
Co
ntr
ols
0..1
1..*
MACHINE
MNo {PK}MDesc
MLocation
ERDCompanyDatabase
manager
staff
DEPENDENTS
DeGender
DeBDateDeBYearDeBMoDeBDay
Relationship
WorksOn
0..*
1..*
0..*
0..*
0..*
DeNameDeLastName
DeFirstNameDeMI
USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
WorksOn {R}
HoursPerMonth
MANAGES {R}
MgrStartDate
Step-6 EDR To Relational - Multi-valued Attribute
-
8/8/2019 Lecture 03 ERD to Relational
54/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYear
EBMoEBDay
/EAge
PROJECT
PrNo {PK}PrNamePrLocation [1..*]
Step-6 EDR To Relational - Multi-valued Attribute
Create New Relations:HasPhone
ProjectLocation
HasPhone
EID EPhone
HasPhone (EID, EPhone )
Project LocationPrNo PrLocatio
n
ProjectLocation (PrNo, PrLocation )
EDR To Relational:COMPANY
-
8/8/2019 Lecture 03 ERD to Relational
55/92
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]
-
8/8/2019 Lecture 03 ERD to Relational
56/92
STEP 7: For each n-ary relationship type R, n>2:
create a new relation Sto represent R.
Include as foreign key attributes in S the primary keys of therelations that represent the participating entity types.
Also, include any simple attributes of the n-aryrelationshiptype (or simple components of composite attributes) as
attributes of S.
Theprimary key of S is usually a combination of all theforeign keys that reference the relations representing theparticipating entity types.
However if the cardinality constraints on any one of the entitytypes E participating inR is1, then the primary key of S
should not include the foreign key attribute that referencesthe relation E corresponding to E.
Tabular Representation of the ER Diagram [EN2007]
Step 7 EDR To Relational: Multi way (Cases)
-
8/8/2019 Lecture 03 ERD to Relational
57/92
S(attribute-a, attribute-1, attribute-i)
Step 7- EDR To Relational: Multi-way (Cases)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..* R
E3
attribute-i{PK}attribute-ii
1..*
0..*
Create a new relation S
Step 7 EDR To Relational: Multi way (Cases)
-
8/8/2019 Lecture 03 ERD to Relational
58/92
S(attribute-a, attribute-1, attribute-i, attribute-r1,attribute-r2)
Step 7- EDR To Relational: Multi-way (Cases)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..*
E3
attribute-i{PK}attribute-ii
1..*
0..*
Create a new relation S
R {R}
attribute-r1attribute-r2
PK
-
8/8/2019 Lecture 03 ERD to Relational
59/92
Step-7 EDR To Relational - Multi-way: Company
-
8/8/2019 Lecture 03 ERD to Relational
60/92
EMPLOYEE
EID {PK}EName
ELastNameEFirstNameEMI
EAddressEStNoEStNameECityECountry
EPhone [0..3]EGenderEBDate
EBYearEBMoEBDay
/EAge
PROJECT
PrNo {PK}PrNamePrLocation [1..*]USE {R}
UseDateStart Time
SHourSMin
End TimeEHourEMin
/HoursPerDay
MACHINE
MNo {PK}MDescMLocation
0..*
0..*
0..*
p y p y
New Relation to be created:USE
USE
EID PrNo MNoUseDate
SHour SMin EHourEMin HoursPerDay
USE ( EID,PrNo,Mno, UseDate, Shour, Smin, Ehour, Emin, HoursPerDay )
EDR To Relational:COMPANY
-
8/8/2019 Lecture 03 ERD to Relational
61/92
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
-
8/8/2019 Lecture 03 ERD to Relational
62/92
Field DataType
LengthRequired
Foreign KeyEID char 10 Not nullELastName char 30 Not nullEFirstName char 30 Not nullEMI char 4EStNo char 5EStName char 20
ECity char 20 Not nullECountry char 20 Not nullEGender char 1 Not nullEBYear Date Not nullEBMo
Date Not nullEBDay Date Not nullEAge intDNo char 5 Not null DEPARTME
NTPNo char 5 Not null POSITION
DEPARTMENT
-
8/8/2019 Lecture 03 ERD to Relational
63/92
DEPARTMENT
Field DataType
LengthRequired
Foreign KeyDNo char 10 Not null
DName char 50 Not nullDLocation char 50 Not nullMgrEID char 10 EMPLOYEEMgrStartDate Date
POSITION
Field DataType
LengthRequired
Foreign KeyPNo char 10 Not nullPName char 50 Not nullSalary money
PROJECT
-
8/8/2019 Lecture 03 ERD to Relational
64/92
PROJECT
Field DataType
LengthRequired
Foreign KeyPrNo char 10 Not nullPrName
char 50 Not nullDNo char 10 Not null DEPARTMENT
MACHINE
Field Data
Type
LengthRequire
d
Foreign Key
MNo char 10 not nullMDesc char 50 Not nullMLocation char 50 Not null
-
8/8/2019 Lecture 03 ERD to Relational
65/92
DEPENDENTS
Field DataType
LengthRequired
Foreign KeyEID char 10 Not null EMPLOYEEDeLastName char 20 Not nullDeFirstName char 20 Not nullDeMI char 4DeGender char 1
DeBYear dateDeBMo dateDeBDay dateRelationship char 50
WorksOn
-
8/8/2019 Lecture 03 ERD to Relational
66/92
Field DataType
LengthRequired
Foreign KeyEID char 10 Not null EMPLOYEEPrNo
char 10 Not null PROJECTHoursPerMonth float
ProjectLocation
Field Data
Type
LengthRequire
d
Foreign KeyPrNo char 10 Not null PROJECTPrLocation char 50 Not null
FRIENDS
Field DataType
LengthRequired
Foreign KeyEID1 char 10 Nut null EMPLOYEEEID2 char 10 Nut null EMPLOYEE
USE
-
8/8/2019 Lecture 03 ERD to Relational
67/92
Field DataType
LengthRequired
Foreign KeyEID char 10 Nut null EMPLOYEEPrNo char 10 Nut null PROJECTMNo char 10 Nut null MACHINEUseDate dateSHour dateSMin date
EHour dateEMin dateHoursPerDay float
HasPhone
Field DataType
LengthRequired
Foreign KeyEID char 10 Not null EMPLOYEEEPhone char 10 Not null
-
8/8/2019 Lecture 03 ERD to Relational
68/92
Exercises
Exercise #1 : Reduce to Relations (Tables)
-
8/8/2019 Lecture 03 ERD to Relational
69/92
Exercise #1 : Reduce to Relations (Tables)
STUDENT
SID {PK}
SNameSDegreeSGPA
FACULTY
FID {PK}FNameFDegree
DNo
COURSE
CCode {PK}CNameCDesc
CUnits
ENROLL {R}
SectionRoomNo
SkedDayStartTimeEndTime
Grade
0..* 1..*
1..*
Exercise #2 : Reduce to Relations (Tables)
-
8/8/2019 Lecture 03 ERD to Relational
70/92
STUDENT
SID {PK}SNameSDegreeSGPA
FACULTY
FID {PK}FNameFDegreeDNo
COURSE
CCode {PK}CName
CDescCUnits
CLASS {W}
Sec {PK}
RoomNoSked
DayStartTimeEndTime
0..*1..*
1..*
ENROLL {R}
Grade
O
fferin
g
0..1
1..*
Sec {PK}
Exercise #3 : Reduce to Relations (Tables)
-
8/8/2019 Lecture 03 ERD to Relational
71/92
SUPPLIER
SName {PK}SAddress
PROJECT
ProjName {PK}ProjDesc
ProjLeader
PART
PartNo {PK}PartDesc
SUPPLY {W}
Quantity
0..1
0..1
0..1
No partial key
1..*1..*
1..*
S-S S-Proj
S-P
ar
t
HOW??Convert therelationship supply to aweak entity
Exercise #4 : Reduce to Relations (Tables)
-
8/8/2019 Lecture 03 ERD to Relational
72/92
SUPPLIER
SName {PK}SAddress
PROJECT
ProjName {PK}ProjDesc
ProjLeader
PART
PartNo {PK}PartDesc
SUPPLY
SupplyNo {PK}Quantity
0..1 0..1
0..1 Primary Key(surrogate key)
1..*1..*
1..*
S-S S-Proj
S-P
ar
t
HOW??Convert the relationshipsupply to a Strong entityand add an artificial orsurrogate key
LOAN-TRAN {W}Exercise #5 : Reduce to Relations (Tables)
-
8/8/2019 Lecture 03 ERD to Relational
73/92
BANK
BkCode {PK}
BkName
BkAddress
ACCT-TRAN{W}AT-Date
AT-Type
AT-Amount
BRANCH {W}
BrAddress
ACCOUNT
AcctNo {PK}
Balance
AcctType
LOAN
LoanNo {PK}
Amount
LoanTypeCUSTOMER
SSN {PK}
CName
CAddress
CPhone
1..1
1..*
BkHasBr
0..1
1..*
Br-Offer-A
cct
0..1
1..*
Br-Offer-A
cct
1..*
0..*
1..*
0..*Cust-Acct
Cust-Loan
LT-Date
LT-Type
LT-Amount
Do-AT
Do
-LT
1..*
1..1
1..*
1..1
LT-No
AT-No
BrNo
Exercise #6 : Reduce to Relations (Tables)
-
8/8/2019 Lecture 03 ERD to Relational
74/92
D
d1{PK}
d2
d3
d4
A
a1{PK}
a2
a3
B
b1{PK}
b2b3
C
c1{PK}
c2c3 [1..*]
c4{d/pk}c5
c6
E {W}
e2
/e3
F
f1{PK}
f2f3
f4R1{R}
r1-1
r1-2
R2{R}
r2-1[1..*]r2-2
{d}r2-3r2-4
R3{R}
r3-1
r3-2
e1
G
g1{PK}
g2
H {W}
h1
h2
I
i1 {PK}
i2
J
j1{PK}
j2
R4{R}
r4-1
r4-2
R5
R6
R7
R8
R10
R9
0 ..*
0..*1..1 1..1
1..*
1..* 1..*
0..1
0..1 0..1
0..1
1..*
1..1
1..*
1..1
0..*
1..*
0..1
1..1
1..1
1..* 0..*
-
8/8/2019 Lecture 03 ERD to Relational
75/92
75
END Thank You!!
MS ACCESS DATA TYPES
-
8/8/2019 Lecture 03 ERD to Relational
76/92
Data type Storage size DescriptionBINARY 1 byte per
character
Any type of data may be stored
in a field of this type. Notranslation of the data (forexample, to text) is made. Howthe data is input in a binaryfield dictates how it will appear
as output.
BIT 1 byte Yes and No values and fieldsthat contain only one of twovalues.
TINYINT 1 byte An integer value between 0 and255.
MS ACCESS DATA TYPES
MS ACCESS DATA TYPES
-
8/8/2019 Lecture 03 ERD to Relational
77/92
Data type Storage Size DescriptionMONEY 8 bytes A scaled integer
between 922,337,203,685,477.5808 and922,337,203,685,477.5807.
DATE 8 bytes A date or time valuebetween the years 100and 9999.
UNIQUEIDENTIFIER 128 bits A unique identificationnumber used withremote procedure calls.
S CC SS S
MS ACCESS DATA TYPES
-
8/8/2019 Lecture 03 ERD to Relational
78/92
Data type Storage size DescriptionREAL 4 bytes A single-precision floating-point valuewith a range of 3.402823E38 to
1.401298E-45 for negative values,1.401298E-45 to 3.402823E38 for positivevalues, and 0.
FLOAT 8 bytes A double-precision floating-point valuewith a range of 1.79769313486232E308to 4.94065645841247E-324 for negativevalues, 4.94065645841247E-324 to1.79769313486232E308 for positivevalues, and 0.
SMALLINT 2 bytes A short integer between 32,768 and32,767. (See Notes)
Data type Storage size Description
INTEGER 4 bytes A long integer between 2,147,483,648
-
8/8/2019 Lecture 03 ERD to Relational
79/92
y g gand 2,147,483,647. (See Notes)DECIMAL 17 bytes An exact numeric data type that holdsvalues from 1028 - 1 through - 1028 - 1.You can define both precision (1 - 28)
and scale (0 - defined precision). Thedefault precision and scale are 18 and 0,respectively.
TEXT 2 bytes per
character
Zero to a maximum of 2.14 gigabytes.IMAGE As required Zero to a maximum of 2.14 gigabytes.
Used for OLE objects.CHARACTER2 bytes percharacter
Zero to 255 characters.
Source Type Target Type
-
8/8/2019 Lecture 03 ERD to Relational
80/92
Source Type Target Type
Java Pre-Type Java Type Java Post-Type Data Element Type
boolean bit
byte tiny integershort small integer
int integerlong long binary
float floatdouble double precision
const char characterchar character varying
const char * long character
char * long textchar * long var character
default long var character
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
81/92
S(attribute-a, attribute-1, attribute-i)
p y
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..* R
Case 1:
Cardinality -All ManyR has no attributes
E3
attribute-i{PK}attribute-ii
1..*
0..*
Create a new relation S
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
82/92
S(attribute-a, attribute-1, attribute-i)
p y
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..* R
Case 2:Mixture of many andone cardinalitiesR has no attributes
E3
attribute-i{PK}attribute-ii
1..*
0..1
Create a new relation S
Do not includein the primarykey (whose
cardinality isone); butinclude as aforeign key
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
83/92
E2(attribute-1, attribute-2, attribute-a, attribute-i)
p y
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..1 R
E3
attribute-i{PK}attribute-ii
1..1
0..1
Modify relation E2 (with total participation)
Case 3:All one cardinalitiesMixture of total and
partialR has no attributes Foreign key
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
84/92
E1(attribute-a, attribute-b, attribute-1, attribute-i)
p y
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
1..1 R
E3
attribute-i{PK}attribute-ii
1..1
1..1
Modify relation E1, E2 or E3 (with total participation)
Case 4-a:All one cardinalitiesAll total participationR has no attributes
Foreign key
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
85/92
p y
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
1..1 R
E3
attribute-i{PK}attribute-ii
1..1
1..1
Case 4-b:All one cardinalitiesAll total participationR has no attributes
S(attribute-a, attribute-b, attribute-1, attribute-2, attribute-i,attribute-ii)
Drop relations E1, E2 and E3 and then create a new relation S
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
86/92
S(attribute-a, attribute-1, attribute-i, attribute-r1,attribute-r2)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..*
E3
attribute-i{PK}attribute-ii
1..*
0..*
Create a new relation S
R {R}
attribute-r1attribute-r2
Case 5:
Cardinality -All ManyR has attributes
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
87/92
S(attribute-a, attribute-1, attribute-i, attribute-r1,attribute-r2)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
0..*
E3
attribute-i{PK}attribute-ii
1..*
0..1
Create a new relation S
R {R}
attribute-r1attribute-r2
Case 6:Mixture of many andone cardinalitiesR has attributes
Do not includein the primarykey (whosecardinality isone); but
include asforeign key
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
88/92
E1(attribute-a, attribute-b, attribute-1,attribute-i,attribute-r1,attribute-r2)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
1..1
E3
attribute-i{PK}attribute-ii
1..1
0..1
Modify either E1 or E2 (with total participation)
R {R}
attribute-r1attribute-r2
Case 7:All one cardinalitiesMixture of total and
partialR has attributes Foreign key
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
89/92
E1(attribute-a, attribute-b, attribute-1, attribute-i,attribute-r1,attribute-r2)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
1..1
E3
attribute-i{PK}attribute-ii
1..1
1..1
Modify any of relations E1, E2 and E3 (total participation)
R {R}
attribute-r1attribute-r2
Case 8-a:All one cardinalitiesAll total participationR has attributes
Foreign key
Step 7- EDR To Relational: Multi-way
-
8/8/2019 Lecture 03 ERD to Relational
90/92
S(attribute-a, attribute-b, attribute-1, attribute-2, attribute-i,attribute-ii, attribute-r1,attribute-r2)
E2
attribute-1{PK}attribute-2
E1
attribute-a{PK}attribute-b
1..1
E3
attribute-i{PK}attribute-ii
1..1
1..1
Drop relations E1, E2 and E3 and then create a new relation S
R {R}
attribute-r1attribute-r2
Case 8-b:All one cardinalitiesAll total participationR has attributes Foreign
key
Attribute Types: Required Vs Optional
-
8/8/2019 Lecture 03 ERD to Relational
91/92
yp q p
Required Attribute - its value mustbe supplied
by the user. It cannotbe left blank (not null). Example: IDNo
Position
Optional Attribute - a field that may be leftblankbecause:
the information may exist but is not currentlyknown, or
because the field doesn't apply to the record at
all.
Example: Phone No
skills
professional exams
Convert the ERD into Relational Schema
-
8/8/2019 Lecture 03 ERD to Relational
92/92
A
a
1
a2
a3
B
b
1
b2
b3
R1
R3
1 1M
Nr1
E
e1
e2
R4
1
N
R
2r2
C
c1
C2
F
f1
f2
R5
r4
D
d1
d2
N
N
M
r
3R6
1N
r5
M
N
C3
C C Cf f
d3
d4