lecture03_

5
1 Reducing ER-Diagrams to Tables Problem: Consider the entities of Project, General Task and Employee in a project management or job shop organization. Specify the relations with typical attributes to represent these entities and the relationships between them. [MH91] EMPLOYEE SSN Bdate Name Sex Address Salary COMPANY DATABSE DEPARTMENT Number Name Location Works_For N 1 Manages StartDate 1 1 Supervision 1 supervisee supervisor N Dependents EMP_DEP Bdate Name Sex Relationship N 1 PROJECT Name Number Location Works_On Hours CONTROLS N N 1 M Dependents Bdate DeName Sex Relationship PROJECT Name PNo Location Dependents-Of Works_On Hours N M N 1 N Supervision CONTROLS Manages StartDate COMPANY DATABSE 1 N 1 1 Works_For EMPLOYEE SSN Bdate Name Sex Address Salary N DEPARTMENT DNo DName DLocation 1 1 Tabular Representation of the ER –EER Diagram [EN94] STEP 1: For each regular entity type E in the ER schema, create a relation R that includes all the simple 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. Dependents Bdate DeName Sex Relationship PROJECT Name PNo Location Dependents-Of Works_On Hours N M N 1 N Supervision CONTROLS Manages StartDate COMPANY DATABSE 1 N 1 1 Works_For EMPLOYEE SSN Bdate Name Sex Address Salary N DEPARTMENT DNo DName DLocation 1 1

Upload: rajinder-sanwal

Post on 08-May-2017

228 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Lecture03_

1

Reducing ER-Diagrams to Tables

Problem: Consider the entities of Project, General Task and Employee in a project management or job shop organization. Specify the relations with typical attributes to represent these entities and the relationships between them. [MH91]

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

COMPANY DATABSE

DEPARTMENT

Number

NameLocation

Works_For

N 1

Manages

StartDate11

Supervision

1 supervisee

supervisor N

Dependents

EMP_DEP

BdateName

Sex

Relationship

N

1

PROJECT

NameNumber Location

Works_On

Hours

CONTROLS

N N

1

M

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

Tabular Representation of the ER –EER Diagram [EN94]

STEP 1:• For each regular entity type E in the ER schema,

create a relation R that includes all the simple 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.

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

Page 2: Lecture03_

2

EMPLOYEE

EMPLOYEE

SSNBdate

Name

Sex

Address

Salary

FName

MI LName

Manila1950/02/0212000FMariaB.Santos02

Makati1960/01/0110000MJuanA.Cruz01

AddressBdateSalarySexLNameMIFNameSSN

Primary key

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

DEPARTMENT

DNo

NameLocation

NameDNo

Primary Key

Multi-valued attribute

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

LocationNamePNo

PROJECT

Name

PNo Location

Primary Key

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 attributes (or simple components of composite attributes) of W as attributes of R.

• In addition, 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 any.

Page 3: Lecture03_

3

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

DEPENDENTS

Son1990/04/04MJun Santos02

Mother1940/03/01FClara Cruz01

RelationshipBdateSexDeNameESSN

Foreign key

Dependents

Bdate

Sex

Relationship

DeName

Primary key

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 one of the relations (let say S) and include as foreign key in S the primary key of T. It is better to choose an entity type with total participation in R in the role of S.

• Include the entire simple attributes (or simple components of composite attributes) of the 1:1 relationship type R as attributes of S.

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

MANAGES

FinancePersonnelName

0201MGRSSN

1992/06/061990/05/05StartDate

D2D3DNo

Manages

StartDate

1 1DEPARTMENT

DNo

NameLocation

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

NameDNo

Primary key

STEP 4:• For each regular (non-weak) binary 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 attributes (or simple components of composite attributes) of the 1:N relationship type as attributes of S.

*** The reason for this is that each entity instance on the N-side is related to at most one entity instance on the 1-side of the relationship type.

Page 4: Lecture03_

4

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

EMPLOYEE

DEPARTMENT

DNo

DName Location

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N 1

Manila

Makati

Address

D21950/02/0212000FMariaB.Santos02

D11960/01/0110000MJuanA.Cruz01

DNoBdateSalarySexLNameMI

FNameSSN

Manila1950/02/0212000FMariaB.Santos02

Makati1960/01/0110000MJuanA.Cruz01

AddressBdateSalarySexLNameMIFNameSSN

Primary key

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. Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

WORKS_ON

30P102

20P101HoursPNoESSN

Works_On

Hours

M NEMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

PROJECT

Name

PNo Location

Primary key

STEP 6:• For each multivalued 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 multivalued attribute is composite, include its simple components.

Page 5: Lecture03_

5

Dependents

BdateDeName

Sex

Relationship

PROJECT

NamePNo Location

Dependents-Of Works_On

HoursN

M

N

1N

Supervision CONTROLS

Manages

StartDate

COMPANY DATABSE

1 N1 1

Works_For

EMPLOYEE

SSN Bdate

Name

Sex

Address

Salary

N DEPARTMENT

DNo

DNameDLocation

1

1

DEPT_LOCATION

Loc2D1Loc1D2Loc3D2

Loc1D1DLocationDNo

DEPARTMENT

DNo

Name DLocation

Primary key

EMPLOYEE(SSN,FName,MI,Lname,Sex, Salary,Bdate, Address, SUPERSSN,DNo)

DEPARTMENT(DNumber,DName,MGRSSN, StartDate)

DEPT_LOCATION(DNo, Location) PROJECT(PNo, PName, Plocation,DNum)WORKS_ON(ESSN,PNo, Hours)DEPENDENT(ESSN, DependentName, Sex,

Bdate, Relationship)

TABLES as RELATIONS 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 participation is constraint (min, max) of one of the entity types E participating in R has max = 1, then the primary key of S can be the single foreign key attribute that references the relation E’ corresponding to E. This is because in this case, each entity e in E will participate in at most one relationship instance of R and hence can uniquely identify that relationship instance.

SUPPLY

Part2

Part1

PartNo

30

20

Quantity

P1B

P1A

PNoSName

SUPPLY

Quantity

SUPPLIER

SName

PROJECT

PNo

PART

PartNo

Primary key

M M

M