data structures and algorithm-mapping relational
TRANSCRIPT
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
1/23
BITSPilaniHyderabad Campus
Dr.R.GururajCS&IS Dept.
Database Design & Applications
(SS ZG 518)
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
2/23
BITS Pilani, Hyderabad Campus
E(E)R to Relational Mapping(Ch. 7)
Content
1. Mapping Regular Entity types
2. Mapping Weak Entity types
3. Mapping 1:1 Relationships
4. Mapping 1:N Relationships
5. Mapping N:M Relationships
6. Mapping Multivalued and Complex attributes
7. Mapping ternary relationships
8. Mapping Class Hierarchies
1 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
3/23
BITS Pilani, Hyderabad Campus
1. Mapping of Regular Entity Types.
For each regular (strong) entity type E in the ER schema,create a relation R that includes all the simple attributes ofE.
Choose one of the key attributes of E as the primary keyfor R.
If the chosen key of E is composite, the set of simpleattributes that form it will together form the primary keyof R.
Mapping entity types
2 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
4/23
BITS Pilani, Hyderabad Campus
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
5/23
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
6/23
BITS Pilani, Hyderabad Campus
3. Mapping of Binary 1:1 Relation Types
For each binary 1:1 relationship type R in the ERschema, identify the relations S and T that correspond tothe entity types participating in R.
There are three possible approaches:1. Foreign Key approach:Choose one of the relations-say S-and include a
foreign key in S that refers to the primary key of T. It is better to choosean entity type with total participation in R in the role of S.
2. Merged relation option:An alternate mapping of a 1:1 relationshiptype is possible by merging the two entity types and the relationshipinto a single relation. This may be appropriate when bothparticipations are total.
3. Cross-referenceor relationship relation option:The third alternativeis to set up a third relation R for the purpose of cross-referencing theprimary keys of the two relations S and T representing the entity types.
Mapping Relationship types
4 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
7/23BITS Pilani, Hyderabad Campus
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
8/23
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
9/23BITS Pilani, Hyderabad Campus
5. Mapping of Binary M:N Relationship Types.
For each regular binary M:N relationship type R, create a newrelationS to represent R.
Include as foreign key attributes in S the primary keys of therelations that represent the participating entity types; theircombination will form the primary keyof S.
Also include any simple attributes of the M:N relationshiptype (or simple components of composite attributes) asattributes of S.
6 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
10/23BITS Pilani, Hyderabad Campus
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
11/23BITS Pilani, Hyderabad Campus
6. Mapping of Multivalued attributes.
For each multivalued attribute A, create a new relation R.
This relation R will include an attribute corresponding to A,plus the primary key attribute K-as a foreign key in R-of therelation that represents the entity type of relationship typethat has A as an attribute.
The primary key of R is the combination of A and K. If themultivalued attribute is composite, we include its simplecomponents.
Mapping Multivaluedattributes
7 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
12/23BITS Pilani, Hyderabad Campus
7. Mapping of N-ary Relationship Types.
For each n-ary relationship type R, where n>2, create a newrelationship S to 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-ary relationship type(or simple components of composite attributes) as attributes ofS.
Example:The relationship type SUPPY in the ER on the next
slide. This can be mapped to the relation SUPPLY shown in the relational
schema, whose primary key is the combination of the three foreignkeys {SNAME, PARTNO, PROJNAME}
Mapping n-ary relationships
8 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
13/23BITS Pilani, Hyderabad Campus
EMPLOYEE
SUPERVISION
Bdate
Ssn
Name
FName
Mint LName
Sex
Address
Salary
Works_for
DEPARTMENT
Name
Number
Location
MANAGES
Start Date
Number ofEmployee
WORKS_ON
CONTROLS
PROJECTDEPENDENTS_OF
Name
Number
Location
Hours
DEPENDENT
Name Sex BdateRelationship
Dependent
(1, 1)
(1, N)
Project
Controlled
project(1, 1)
(0, N)Controlling
department
(4, N)
department
(1, 1)
(0, N)
(0, 1)
Employee
(1, 1)
(0, 1)
Manager
Employee
SupervisorSupervisor
(0, N)
ER-Diagram for CompanyDatabase
9 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
14/23BITS Pilani, Hyderabad Campus
ER-Relational mapping forCompany Database
10 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
15/23BITS Pilani, Hyderabad Campus
Mapping ternary relationship
11 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
16/23BITS Pilani, Hyderabad Campus
8. Options for Mapping Specialization or Generalization.
Option 8A: Multiple relations-Superclass andsubclasses
Option 8B: Multiple relations-Subclass relations only
Option 8C: Single relation with one type attribute
Option 8D: Single relation with multiple typeattributes
Mapping Class hierarchies
12 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
17/23BITS Pilani, Hyderabad Campus
Option 8A: Multiple
relations-Superclass
and subclasses
13 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
18/23BITS Pilani, Hyderabad Campus
Option 8B: Multiple
relations-Subclass
relations only
14 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
19/23BITS Pilani, Hyderabad Campus
Option 8C: Single
relation with
one type attribute
Ssn Fname Minit Lname Birthdatae Address jobtype Typing speed Tgrade EngType
EMPLOYEE
15 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
20/23
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
21/23BITS Pilani, Hyderabad Campus
Exercise problem
17 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
22/23
BITS Pilani, Hyderabad Campus18 08/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/13/2019 DATA STRUCTURES AND ALGORITHM-MAPPING RELATIONAL
23/23
Summary
We have learnt the rules and guidelines for
mapping ER to Relational model.
Rules for mapping Entity typesRules for mapping Relationships
Rules for mapping Class hierarchies