1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer...

23
1 1 Converting ER Converting ER model Into model Into Relational Relational Table Table Tarek El-Shishtawy Tarek El-Shishtawy Professor Ass. Of Computer Professor Ass. Of Computer Engineering Engineering

Transcript of 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer...

Page 1: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

11

Converting ER Converting ER model Into model Into

Relational TableRelational Table

Tarek El-ShishtawyTarek El-ShishtawyProfessor Ass. Of Computer EngineeringProfessor Ass. Of Computer Engineering

Page 2: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

22

Mapping Regular EntitiesMapping Regular Entities

Each regular entity type in an ER diagram Each regular entity type in an ER diagram is transformed into a relation. The name is transformed into a relation. The name given to the relation is generally the same given to the relation is generally the same as the entity type.as the entity type.

Each simple attribute of the entity type Each simple attribute of the entity type becomes an attribute of the relation. – The becomes an attribute of the relation. – The identifier of the entity type becomes the identifier of the entity type becomes the primary key of the corresponding relation.primary key of the corresponding relation.

Page 3: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

33

ExampleExample

Entity name = Name of the relation or table.Entity name = Name of the relation or table. Attributes of ER diagram=Column name of the table.Attributes of ER diagram=Column name of the table.

Table PLAYERPlayer Name Nation Position Number of wonRoger Federer Switzerland 1 5 Roddick USA 2 4

Page 4: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

44

Example using Oracle designer Example using Oracle designer notationsnotations

Page 5: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

55

Converting Composite AttributeConverting Composite Attribute

only the simple component attributes of the composite only the simple component attributes of the composite attribute are included in the relation. attribute are included in the relation.

CUSTOMER

Customer-IDNameStreetCityStateZip

Page 6: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

66

Mapping Multivalued Attributes in ER Mapping Multivalued Attributes in ER

One way to map a multivalued attribute is One way to map a multivalued attribute is to create two tables.to create two tables.

Page 7: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

77

Converting “Weak Entities”Converting “Weak Entities”

m1

Page 8: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

88

Converting “Weak Entities” Converting “Weak Entities”

For each weak entity type, create a new relationFor each weak entity type, create a new relation All of the simple attributes as attributes of the All of the simple attributes as attributes of the

relation. relation. The primary key of the identifying relation as a The primary key of the identifying relation as a

foreign key attribute to this new relation. foreign key attribute to this new relation. The primary key of the new relation is the The primary key of the new relation is the

combination of the primary key of the identifying combination of the primary key of the identifying and the partial identifier of the weak entity type. and the partial identifier of the weak entity type.

In this example DEPENDENT is weak entity.In this example DEPENDENT is weak entity.

Page 9: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

99

Converting “Weak Entities”Converting “Weak Entities”

Page 10: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1010

Converting Binary Relationship Converting Binary Relationship Mapping one-to-Many RelationshipMapping one-to-Many Relationship

One customer can give many orders.

m

1

Page 11: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1111

Mapping one-to-Many RelationshipMapping one-to-Many Relationship

Page 12: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1212

Using Oracle Designer notationUsing Oracle Designer notation

Page 13: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1313

Binary one-to-one relationship Binary one-to-one relationship

Can be viewed as a special case of one-Can be viewed as a special case of one-to-many relationships. to-many relationships.

First, two relations are created, one for First, two relations are created, one for each of the participating entity types. each of the participating entity types.

Second, the primary key of one of the Second, the primary key of one of the relations is included as a foreign key in the relations is included as a foreign key in the other relation.other relation.

Example Parking place and employee Example Parking place and employee

Page 14: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1414

Many to Many relationshipsMany to Many relationships

M-M Needs an intersection tableM-M Needs an intersection tableNote: Pre-requests requires more additional Note: Pre-requests requires more additional

tabletable

Page 15: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1515

Many to Many relationshipsMany to Many relationships

EM P_ ID NAM E OTHER S

CR S_ ID T IT LE S

CR S_ ID PR EREQ

EM P_ ID CR S_ ID

EM PLOYEE

COUR SE

EM PLOYEE _COUR SE

Page 16: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1616

Mapping Associative Entity to TablesMapping Associative Entity to TablesWithout IdentifierWithout Identifier

Page 17: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1717

Mapping Associative Entity to TablesMapping Associative Entity to Tables

Page 18: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1818

Mapping Associative Entity to TablesMapping Associative Entity to TablesWith IdentifierWith Identifier

Page 19: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

1919

Mapping Associative Entity to TablesMapping Associative Entity to TablesWith IdentifierWith Identifier

Page 20: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

2020

Converting Unary RelationshipConverting Unary Relationship

Each employee has exactly one manager. A given employee may manage zero to many employees. The foreign key in the relation is named Manager-ID

Page 21: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

2121

Converting Unary RelationshipConverting Unary Relationship

Page 22: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

2222

Converting Ternary RelationshipConverting Ternary Relationship

Page 23: 1 Converting ER model Into Relational Table Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

2323

Converting Ternary RelationshipConverting Ternary Relationship