SlideShare a Scribd company logo
1 of 11
Download to read offline
Course Notes on
From Entity-Relationship Schemas to Relational
Schemas
• The chapter deals with practical database design:
3 the construction of a relational schema from an E-R schema
3 this stage of database design is sometimes called “logical design”, besides concep-
tual design (the construction of the E-R schema), physical design (the represen-
tation of relations as files on disk and the choice of index structures) depending
on the specific DBMS chosen and a given mix of application programs
• CASE tools often
3 permit to build E-R schemas interactively
3 apply a version of the translation rules presented in this chapter
• The relational model is poorer than the E-R model: the translation from an E-R
schema to a relational schema entails a loss in the quality of the correspondence
between the database schema and the appplication domain
From E-R to Relational Schemas: Summary
(1) Suppressing generalizations from ER schemas
• Keeping the superentity
• Keeping the subentity
• Modeling by ordinary relationships
(2) ER-to-relational mapping
• Entities, weak entities
• Relationships
• Multi-valued attributes
(3) Direct mapping of generalizations to relations
1
From Entity-Relationship to Relational Schemas, September 22, 2008 – 1
Suppressing Generalizations from ER Schemas
• The semantics of generalization to be preserved:
3 mechanism of property inheritance
3 is-a relationship (subentities are also instances of the superentity class)
• The solutions only approximate a faithful translation:
3 suppress subentity classes and express generalization semantics with the su-
perclass
3 retain subentity classes only
3 model generalization as ordinary relationships
2
From Entity-Relationship to Relational Schemas, September 22, 2008 – 2
Keeping the Superentity: Example
Student
Graduate
Student
Exchange
Student
SSN
Name
Major
Advisor
(1,1)
Visits
(0,1)
(1,n)(1,n)
ThesisTitle Option
Professor University
Student
SSN
Name
Major
Rank (0,1)
ThesisTitle (0,1)
Option (0,1)
Advisor
(1,1)
Visits
(0,1)
(1,n)(1,n)
Professor University
(p,e)
3
• Transformation for the example:
3 suppress subentities Graduate Student and Exchange Student
3 propagate attributes and relationships of subentities to superentity Student, with
optional participation (minimal cardinality of 0)
3 add a new discriminating attribute (Rank) with values that refer to the former
subclasses (for example, GradStud and ExchStud)
• Constraints are necessary in the transformed schema to preserve specific properties
(attributes and relationships) of subentities in the initial schema:
3 all and only students with Rank = GradStud have an advising Professor and a Thesis
Title
3 only Students with Rank = ExchStud may visit another University
3 all and only Students with Rank = ExchStud have an Option
From Entity-Relationship to Relational Schemas, September 22, 2008 – 3
Transformation Keeping the Superentity
• Properties of subentities are propagated to the superentity
3 attributes become optional
3 relationships become optional on the side of superentity
• A new (discriminating) attribute is added to the superentity with
cardinality
(0,n)
(1,n)
(0,1)
(1,1)
for generalization
partial, overlapping
total, overlapping
partial, exclusive
total, exclusive
• Constraints are added between the discriminating attribute and
3 attributes of subentities
3 participation of subentities in relationships
4
Keeping the Superentity: Evaluation
• Drawbacks
3 optional attributes are introduced (null values)
3 operations concerning subentities now have to be expressed via the superen-
tity: application programs become more complex
3 many constraints become explicit
• Advantage: simple, always applicable
5
From Entity-Relationship to Relational Schemas, September 22, 2008 – 4
Keeping the Subentities: Example
Employee
Secretary Engineer
SSN
Name
Uses
(1,n)
Supervision
(0,1)
(0,n)
(0,n)
Skills (1,n) Speciality
Word
Processor
Manager
NbSuperv
WorksOn
(0,1) (1,n)
Project
Name
Budget
(t,e)
6
Keeping the Subentities: Translation of the Example
Secretary Engineer
Uses
(1,n)
(0,n)
SSN
Name
Skills (1,n)
SSN
Name
Speciality
Word
Processor
Manager
SSN
Name
NbSuperv
WorksOn3
(0,n)
Project
Name
Budget
Supervision2
WorksOn1
(0,1) (0,1) (0,1)
WorksOn2
(0,n) (0,n)(0,n)
Supervision2
Supervision3
(0,1) (0,1)
(0,n)
(0,n)
(0,1) Subordinate
Supervisor
7
From Entity-Relationship to Relational Schemas, September 22, 2008 – 5
• Attributes of Employee (SSN, Name), and relationships WorksOn and Supervision are
made explicit for each subentity
• SSN is an identifier for each of Secretary, Engineer, and Manager
• Constraint: the values of SSN must be unique across all three entity types
Keeping the Subentities: Evaluation
• Method: propagate to each subentity the attributes (and identifiers) and rela-
tionship links of the superentity
• Drawbacks
3 proliferation of essentially redundant attributes and relationships
3 application programs become more complex (operations on the superentity
must now access all subentities)
3 inter-relation constraint (corresponding to identifier of superentity)
• Only applicable to total-and-exclusive generalizations
8
• Exercise:
3 it is easy to transform any generalization into a total-and-exclusive generalization
3 this may lead to creating entities that were not naturally identified in the first
place
From Entity-Relationship to Relational Schemas, September 22, 2008 – 6
Modeling with Relationships: Example
Project
HwProject SwProject
SSN
Name
#Boards ManMonth
Subcontract
Contractor
WorksOn
(1,n) (1,n)
Employee
Name
Budget
(p,o)
Uses
(1,n)
(0,n)
Component
9
Modeling with Relationships: Translation of the Example
Project
HwProject SwProject
SSN
Name
Uses
(1,n)
(0,n)
#Boards ManMonth
Component
Subcontract
Contractor
WorksOn
(1,n) (1,n)
Employee
Name
Budget
IsHwProj
(0,1)
(1,1)
IsSwProj
(0,1)
(1,1)
IsSubcont
(0,1)
(1,1)
10
From Entity-Relationship to Relational Schemas, September 22, 2008 – 7
Modeling with Relationships: Evaluation
• New relationships are created (IsHwProj, ...): they are mandatory on subentities,
optional on superentity
• Former subentities have become weak entities with the former superentity as
identifying entity
• Old attributes and relationships are preserved
• Drawbacks:
3 redundancy (the new relationships have the same meaning)
3 constraints are needed to express the type of generalization (totality, exclu-
siveness)
3 some operations become more complex (e.g., insertion of a subtentity requires
insertion of superentity)
11
ER-to-Relational Mapping
• Derivation of a relational schema equivalent to a given ER schema without gen-
eralizations
• Versions of the translation are realized by CASE tools for database design, that
produce relational schemas in the DDL of specific DBMSs
• The basic translation can be realized with a few rules
12
From Entity-Relationship to Relational Schemas, September 22, 2008 – 8
Company: ER Schema
WorksFor
(1,1)
(4,n)
Employee
SSN
Name
FName
MInit
LName
BDate
Sex
Salary
Address
Department
Number
Name
Locations (1,n)
/NoEmployees
Controls
Project
Number
Name
Location
WorksOn
hours
Supervision
(1,n)
(1,n)
(1,n)
(1,1)
(1,1)
(0,1)
(0,1)(0,n)
SuperviseeSupervisor
Manages
startDate
Name
Sex
BDate
Relationship
DependOf
(0,n)
(1,1)
Dependent
13
Company: Relational Representation
Employee
SSN MInit LName BDate Address Sex Salary SuperSSN DNo
Department
DNumber DName DMgr MgrStartDate
DeptLocations
DNumber DLocation
Project
PNumber PName PLocation DNumber
WorksOn
PNo ESSN Hours
Dependent
ESSN DependentName Sex BDate Relationship
14
From Entity-Relationship to Relational Schemas, September 22, 2008 – 9
• relations Employee, Department, Project represent entities (entity relations)
• relation Employee also represents one-to-many relationships WorksFor and Supervision,
relation Department represents one-to-one relationship Manages, relation Project rep-
resents one-to-many relationship Controls
• relation DeptLocations represents multivalued attribute Locations of entity Department
• relation WorksOn represents the many-to-many relationship WorksOn between Em-
ployee and Project (relationship relation)
• relation Dependent merges relationship DependOf and weak entity Dependent
Rule 1: Entity Type
For each nonweak entity type E, create a relation R with
• all simple attributes of E
• the simple components of composite attributes of E (there is no notion of com-
posite attribute in the relational model)
• keys of R corresponding to identifiers of E
Employee
SSN FName MInit LName BDate Address Sex Salary
Department
DNumber DName
Project
PNumber PName PLocation
15
• More attributes will be added to R by subsequent rules to represent some of the 1-1
and 1-N relationships of the entity type represented by R
• Relations like R are sometimes called entity relations
From Entity-Relationship to Relational Schemas, September 22, 2008 – 10
Rule 2: Weak Entity Type
For each weak entity type F, create a relation R with
• all simple attributes of F
• simple components of composite attributes of F
• as foreign key of R (i.e., with a referential integrity constraint), attribute(s) cor-
responding to the primary key of the relation (produced by Rule 1) representing
the entity identifying F
• primary key of R = this foreign key + attributes of partial key of F
Dependent
ESSN DependentName Sex BDate Relationship
16
• Note that Rule 2 represents in relation R both the weak entity F and its relationship
to the entity that contributes to identifying F
• Remember that binary relationships R between E1 and E2 can be:
3 one-to-one (1-1) if the maximal cardinality of both E1 and E2 in R is 1
3 one-to-many (1-N) if the maximal cardinality of one of E1 and E2 in R is 1 and
the other maximal cardinality is ¿ 1
3 many-to-many (M-N) if the maximal cardinality of both E1 and E2 in R is ¿ 1
• Basic ideas of the following rules for mapping relationships to relations:
3 1-1 and 1-N relationships can be represented by a foreign-key attribute (i.e.,
with referential integrity) in the relation representing the entity whose maximal
cardinality in R is 1 (Rules 3 and 4)
3 each M-N relationship is mapped to a relation (Rule 5)
3 1-1 and 1-N relationships can also be mapped to a relation (by Rule 5)
3 each N-ary relationship is mapped to a relation (Rule 7)
From Entity-Relationship to Relational Schemas, September 22, 2008 – 11
Rule 3: 1-1 Binary Relationship
• Let R be a 1-1 relationship between entity types E1 and E2 (modeled as relations
R1 and R2)
• Choose R1 (or R2) to represent R; include in R1:
3 as foreign key (i.e., with referential integrity) the primary key of R2
3 the simple attributes and the simple components of the composite attributes
of R
• If the minimal cardinality of E1 in R is 0, there will be null values in the extension
of R1
Department
. . . DMgr MgrStartDate
17
• When choosing between R1 and R2 to represent relationship R, it is preferrable to
choose the relation corresponding to an entity (E1 or E2) that is total in R (minimal
cardinality = 1) in R: thos choice mimimizes null values in the chosen relation
• Other possible representations for a 1-1 relationship:
3 R could also be represented by a relation, using Rule 5 (this solution is sometimes
advocated to minimize null values, when the minimum cardinality of both E1 and
E2 in R is 0)
3 R, E1, and E2 could all be represented in a single relation with two keys, each
corresponding to the identifier of E1 and E2
From Entity-Relationship to Relational Schemas, September 22, 2008 – 12
Rule 4: 1-N Binary Relationship
• Let R be a 1-N relationship between entity types E1 and E2 (modeled as relations
R1 and R2), with maximal cardinality of E1 = 1 and maximal cardinality of E2
= N
• Include in R1
3 as foreign key (i.e., with referential integrity) the primary key of R2
3 the simple attributes and the simple components of the composite attributes
of R
Employee
. . . SuperSSN DNo
18
Rule 5: M-N Binary Relationship
• Let R be an M-N relationship between entity types E1 and E2 (modeled as
relations R1 and R2)
• Relationship R is represented as a relation R with:
3 as foreign keys (i.e., with referential integrity) the primary keys of R1 and R2
3 a composite primary key made of those two foreign keys
3 attributes corresponding to the simple attributes and to the simple compo-
nents of the composite attributes of relationship R
• This representation can also apply to 1-1 and 1-N relationships, thereby avoiding
null values in relations
• Relations like R are sometimes called relationships relations
WorksOn
ESSN PNo Hours
19
From Entity-Relationship to Relational Schemas, September 22, 2008 – 13
Rule 6: Multivalued Attribute
• Let V be a multivalued attribute of an entity type E, and R1 be the relation
representing E
• Create a relation R with an attribute V and attribute(s) K for the primary key
of R1 as foreign key of R (i.e., with referential integrity)
• Primary key of R = V ∪ K
• Problem: information about E (Departments) is split in 2 relations R and R1
DeptLocations
DNumber DLocation
20
What Multivalued Relational Attributes Could Look Like
Department
DName DNumber DMgr {DLocations}
6 6 6
Department
DName DNumber DMgr {DLocations}
Research 5 333445555 {Bellaire,Sugarland,Houston}
Administration 4 987654321 {Stafford}
Headquarters 1 888665555 {Houston}
• Multivalued attributes are not permitted in the relational model (“repeating
groups” existed in its predecessors COBOL and CODASYL)
• This would be a natural extension, but with more complex definitions for
3 the DML (algebra, calculi, SQL)
3 functional dependencies
21
From Entity-Relationship to Relational Schemas, September 22, 2008 – 14
Rule 6 as Normalization of Multivalued Attributes into 1NF
Department
DName DNumber DMgr {DLocations}
Research 5 333445555 {Bellaire,Sugarland,Houston}
Administration 4 987654321 {Stafford}
Headquarters 1 888665555 {Houston}
⇓ 1NF Normalization
Department
DName DNumber DMgr
Research 5 333445555
Administration 4 987654321
Headquarters 1 888665555
DeptLocations
DNumber DLocation
5 Bellaire
5 Sugarland
5 Houston
4 Stafford
1 Houston
22
Single-Relation Representation of Multivalued Attributes
Department
DName DNumber DMgr {DLocations}
Research 5 333445555 {Bellaire,Sugarland,Houston}
Administration 4 987654321 {Stafford}
Headquarters 1 888665555 {Houston}
⇓ 1NF Normalization
Department
DName DNumber DLocation DMgr
Research 5 Bellaire 333445555
Research 5 Sugarland 333445555
Research 5 Houston 333445555
Administration 4 Stafford 987654321
Headquarters 1 Houston 888665555
23
From Entity-Relationship to Relational Schemas, September 22, 2008 – 15
• The relational model, when it was defined in the early 1970’s, ruled out multival-
ued attributes to mark a clear simplification in comparison to the previously existing
models (COBOL, Codasyl)
• Multivalued attributes are natural and useful, they were present as “repeating groups”
in the pre-relational era, and are available in all object models
• There is no good relational representation for E-R multivalued attributes:
3 the two-relation solution separates information that naturally goes together
in the real world (the Location information is clearly a property of Departments)
3 the idea of the single-relation solution is to keep together pieces of information
that concern the original entity
∗ the information about Department is represented in a single relation, the join
of relations Department and DeptLocations in the two-relation representation
∗ this introduces redundancy (several tuples for each department with more
than one location)
∗ the tuples of the join relation do not have a simple correspondence with thd
real-world perception: a tuple represents information about one department
AND one of its locations (not just about one department)
Rule 7: N-ary Relationship (n > 2)
Create a relation Rel that represents the n-ary relationship R, with
• simple attributes of R and simple components of composite attributes of R
• as foreign keys (i.e., with referential integrity), the primary keys of relations that
represent the entity types of R
• a composite primary key made of those foreign keys
(except if an entity type E of R has maximum cardinality 1 in R, in which case
the primary key of Rel is the primary key of the relation that represents E)
24
From Entity-Relationship to Relational Schemas, September 22, 2008 – 16
N-ary Relationship: Example
Supplier Supply
(0,n)
Project
(0,n)
Part
(0,n)
PartNo
ProjNameSupName Quantity
Supplier
SupName . . .
Project
ProjName . . .
Part
PartNo . . .
Supply
SupName ProjName PartNo Quantity
25
• The composite key of relation Supply is made of SupName, ProjName, and PartNo
• There is a referential integrity constraint from each of those attributes to the corre-
sponding attribute in relations Supplier, Project, and Part
From Entity-Relationship to Relational Schemas, September 22, 2008 – 17
Direct Relational Mapping of Generalization
Secretary Technician
SSN
Name
BirthDate
TypingSpeed TechGrade
Engineer
EngType
Employee
(t,e)
Generalization can be mapped directly to relations, by combining the previous rules
for generalization elimination and E-R to relational mapping, with 3 solutions:
• a relation for the superentity only
• relations for subentities only
• relations for both super- and subentities
26
Generalization: Single Relation for Superentity
• For a generalization with subclasses {S1, . . . , Sm} and a superclass S where the
attributes of S are {k, a1, . . . , am} and k is an identifier of S
• Create a single relation L with
3 attributes {k, a1, . . . , am} ∪ {attributes of S1} ∪ . . . {attributes of Sn} ∪ {t}
3 primary key = k
3 t : new (“discriminating”) attribute, keeping track of subentities (JobType)
3 null values possible for subclass attributes (with constraints via t values)
Employee
SSN FName . . . TypingSpeed TechGrade EngType JobType
27
From Entity-Relationship to Relational Schemas, September 22, 2008 – 18
Generalization : Relations for Subentities Only
• For a generalization with subclasses {S1, . . . , Sm} and a superclass S where the
attributes of S are {k, a1, . . . , am} and an identifier of S is k
• Create a relation Li for each subclass Si with
3 attributes {attributes of Si} ∪ {k, a1, . . . , am}
3 primary key k, with unicity constraint across all Li’s
Secretary
SSN FName . . . TypingSpeed
Technician
SSN FName . . . TechGrade
Engineer
SSN FName . . . EngType
28
Generalization: Relations for Both Super- and Subentities
• For a generalization with subclasses {S1, . . . , Sm} and a superclass S where the
attributes of S are {k, a1, . . . , am} and an identifier of S is k
3 create a relation L for S with attributes
{k, a1, . . . , am} and primary key k
3 create a relation Li for each Si with attributes {k} ∪ {attributes of Si} and
primary key k
Employee
SSN FName MInit LName BirthDate Address
Secretary
SSN TypingSpeed
Technician
SSN TechGrade
Engineer
SSN EngType
29
From Entity-Relationship to Relational Schemas, September 22, 2008 – 19
Relations for Both Super- and Subentities: a Variant
• Add a (redundant) view for each subclass, by joining the subclass relation with
the superclass relation
• Advantages
3 “materializing” attribute inheritance
3 saving a join in queries that involve inherited attributes
Employee
SSN FName MInit LName BirthDate Address
Secretary
SSN TypingSpeed
Full-Secr
SSN FName MInit LName BirthDate Address TypingSpeed
30
Entity Relationship versus Relational: Summary
• ER schema is more compact (a connected graph) than relational schema (a
collection of relations) ⇒ easier and more intuitive perception of information
content
• ER model has two main constructs: entities and relationships
• Relational model only has relations, used as
3 “entity” relations (e.g., Employee, Department, Project, Dependent)
3 “relationship” relations (e.g., WorksOn)
3 “multivalued-attribute” relations (e.g., DeptLocations)
31
From Entity-Relationship to Relational Schemas, September 22, 2008 – 20
Loss of Information in the ER-to-Relational Translation
• Information loss relates to the quality of the correspondence between data model
and the underlying real world
3 loss of precision: a single relational construct (relation) represents three ER
constructs (entity, relationship, multivalued attribute)
3 the ER model was created after the relational model, to distinguish differ-
ent types of relations (entity relations, relationship relations, multivalued
attributes)
• Good correspondence between ER schema and relational schema depends on
3 constraints (multiple referential integrity constraints, constraints for cardi-
nalities)
3 documentation: informal description of the links between relations and
concepts perceived in the real world
32
Issues for Database Design and Efficiency
• 1-1 and 1-N relationship can be merged into the relation representing one of the
participating entities or preserved as ”relationship” relations (Rules 3 and 4)
• Pros of merging
3 fewer relations (simpler schemas)
3 fewer joins in queries
• Cons of merging
3 relationships as independent constructs essentially disappear
3 more complexity from asymmetry of relationship representation
3 reduced extensibility (difficulty to get cardinalities right directly)
• Representing multivalued attributes with two relations (Rule 6) is also a source
of joins in queries
33
From Entity-Relationship to Relational Schemas, September 22, 2008 – 21

More Related Content

What's hot

Ch 6 Logical D B Design
Ch 6  Logical D B  DesignCh 6  Logical D B  Design
Ch 6 Logical D B Design
guest8fdbdd
 
Basic database analysis(database)
Basic database analysis(database)Basic database analysis(database)
Basic database analysis(database)
welcometofacebook
 
Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2
eidah20
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
Nikhil Deswal
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
Jafar Nesargi
 
Logical database design and the relational model(database)
Logical database design and the relational model(database)Logical database design and the relational model(database)
Logical database design and the relational model(database)
welcometofacebook
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mapping
Shubham Saini
 

What's hot (20)

Chapter 9
Chapter 9Chapter 9
Chapter 9
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
 
Ch 6 Logical D B Design
Ch 6  Logical D B  DesignCh 6  Logical D B  Design
Ch 6 Logical D B Design
 
Basic database analysis(database)
Basic database analysis(database)Basic database analysis(database)
Basic database analysis(database)
 
Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2
 
Erd chapter 3
Erd chapter 3Erd chapter 3
Erd chapter 3
 
Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
Relational model
Relational modelRelational model
Relational model
 
Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)
 
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database ConstraintsThe Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
The Relational Model
The Relational ModelThe Relational Model
The Relational Model
 
Logical database design and the relational model(database)
Logical database design and the relational model(database)Logical database design and the relational model(database)
Logical database design and the relational model(database)
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
 
Relational model
Relational modelRelational model
Relational model
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mapping
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 

Viewers also liked

alloy wheels private limited
alloy wheels private limitedalloy wheels private limited
alloy wheels private limited
innocent_devil
 
Haroon Usman's DFM Professional Report
Haroon Usman's DFM Professional ReportHaroon Usman's DFM Professional Report
Haroon Usman's DFM Professional Report
Haroon Usman
 
Cornell Notes + Abbreviations
Cornell Notes + AbbreviationsCornell Notes + Abbreviations
Cornell Notes + Abbreviations
jmori1
 
Mongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guideMongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guide
Philip Zhong
 
Photo album latest slideshow1
Photo album latest slideshow1Photo album latest slideshow1
Photo album latest slideshow1
hussain56
 
Ig1 assignment 2011_to_2012_updated_17.01.12
Ig1 assignment 2011_to_2012_updated_17.01.12Ig1 assignment 2011_to_2012_updated_17.01.12
Ig1 assignment 2011_to_2012_updated_17.01.12
FirstClassProductions
 
Эффективный рекламный продукт
Эффективный рекламный продуктЭффективный рекламный продукт
Эффективный рекламный продукт
Kyryl Ivanov
 

Viewers also liked (20)

alloy wheels private limited
alloy wheels private limitedalloy wheels private limited
alloy wheels private limited
 
Haroon Usman's DFM Professional Report
Haroon Usman's DFM Professional ReportHaroon Usman's DFM Professional Report
Haroon Usman's DFM Professional Report
 
Design and Structural Analysis of Alloy Wheels for Light Weight Vehicles
Design and Structural Analysis of Alloy Wheels for Light Weight Vehicles Design and Structural Analysis of Alloy Wheels for Light Weight Vehicles
Design and Structural Analysis of Alloy Wheels for Light Weight Vehicles
 
Wheel Design & Analysis
Wheel Design & AnalysisWheel Design & Analysis
Wheel Design & Analysis
 
Car Basics
Car BasicsCar Basics
Car Basics
 
Cornell Notes + Abbreviations
Cornell Notes + AbbreviationsCornell Notes + Abbreviations
Cornell Notes + Abbreviations
 
Quickintro2webapps
Quickintro2webappsQuickintro2webapps
Quickintro2webapps
 
Trends gartner iam-amit12-4-12
Trends gartner iam-amit12-4-12Trends gartner iam-amit12-4-12
Trends gartner iam-amit12-4-12
 
Mongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guideMongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guide
 
ใบงาน ม.2
ใบงาน ม.2ใบงาน ม.2
ใบงาน ม.2
 
Photo album latest slideshow1
Photo album latest slideshow1Photo album latest slideshow1
Photo album latest slideshow1
 
Lommi: Kouluterveyskysely 2010 Itä-Suomessa
Lommi: Kouluterveyskysely 2010 Itä-SuomessaLommi: Kouluterveyskysely 2010 Itä-Suomessa
Lommi: Kouluterveyskysely 2010 Itä-Suomessa
 
Xavier thoma
Xavier thomaXavier thoma
Xavier thoma
 
M robby f_mi2b_tugas 2
M robby f_mi2b_tugas 2M robby f_mi2b_tugas 2
M robby f_mi2b_tugas 2
 
366/14 MediaKey /// Creatività: Made in Tunnel Studios
366/14 MediaKey /// Creatività: Made in Tunnel Studios366/14 MediaKey /// Creatività: Made in Tunnel Studios
366/14 MediaKey /// Creatività: Made in Tunnel Studios
 
Ig1 assignment 2011_to_2012_updated_17.01.12
Ig1 assignment 2011_to_2012_updated_17.01.12Ig1 assignment 2011_to_2012_updated_17.01.12
Ig1 assignment 2011_to_2012_updated_17.01.12
 
Эффективный рекламный продукт
Эффективный рекламный продуктЭффективный рекламный продукт
Эффективный рекламный продукт
 
Codigos de barras
Codigos de barrasCodigos de barras
Codigos de barras
 
Pemodelan Geografi berbasis AHP
Pemodelan Geografi berbasis AHPPemodelan Geografi berbasis AHP
Pemodelan Geografi berbasis AHP
 
Slideshow
SlideshowSlideshow
Slideshow
 

Similar to Ertorelnotes

entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
IRWANBINISMAILKPMGur1
 
Entity relationship modelling - DE L300
Entity relationship modelling - DE L300Entity relationship modelling - DE L300
Entity relationship modelling - DE L300
Edwin Ayernor
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
LPhct2
 

Similar to Ertorelnotes (20)

entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
 
Entity relationship modelling - DE L300
Entity relationship modelling - DE L300Entity relationship modelling - DE L300
Entity relationship modelling - DE L300
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
2 er
2 er2 er
2 er
 
ER model
ER modelER model
ER model
 
Week 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data ModelWeek 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data Model
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
Islamic University Previous Year Question Solution 2019 (ADBMS)
Islamic University Previous Year Question Solution 2019 (ADBMS)Islamic University Previous Year Question Solution 2019 (ADBMS)
Islamic University Previous Year Question Solution 2019 (ADBMS)
 
Module 1 session 5
Module 1   session 5Module 1   session 5
Module 1 session 5
 
ERD.ppt
ERD.pptERD.ppt
ERD.ppt
 
ERD.ppt
ERD.pptERD.ppt
ERD.ppt
 
Normalization
NormalizationNormalization
Normalization
 
18306_lec-2 (1).ppt
18306_lec-2 (1).ppt18306_lec-2 (1).ppt
18306_lec-2 (1).ppt
 
Normalization1
Normalization1Normalization1
Normalization1
 
Unit 02 dbms
Unit 02 dbmsUnit 02 dbms
Unit 02 dbms
 
3 relational model
3 relational model3 relational model
3 relational model
 
Distributed DBMS - Unit 2 - Overview of RDBMS
Distributed DBMS - Unit 2 - Overview of RDBMSDistributed DBMS - Unit 2 - Overview of RDBMS
Distributed DBMS - Unit 2 - Overview of RDBMS
 
Db1 04
Db1 04Db1 04
Db1 04
 
L7 er2
L7 er2L7 er2
L7 er2
 

Recently uploaded

Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
poojakaurpk09
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
Ken Fuller
 
Escorts Service Cambridge Layout ☎ 7737669865☎ Book Your One night Stand (Ba...
Escorts Service Cambridge Layout  ☎ 7737669865☎ Book Your One night Stand (Ba...Escorts Service Cambridge Layout  ☎ 7737669865☎ Book Your One night Stand (Ba...
Escorts Service Cambridge Layout ☎ 7737669865☎ Book Your One night Stand (Ba...
amitlee9823
 
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...
Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...
Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
anilsa9823
 
OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理
cowagem
 
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
CALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual service
anilsa9823
 
Bur Dubai Call Girl Service #$# O56521286O Call Girls In Bur Dubai
Bur Dubai Call Girl Service #$# O56521286O Call Girls In Bur DubaiBur Dubai Call Girl Service #$# O56521286O Call Girls In Bur Dubai
Bur Dubai Call Girl Service #$# O56521286O Call Girls In Bur Dubai
parisharma5056
 

Recently uploaded (20)

VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
CFO_SB_Career History_Multi Sector Experience
CFO_SB_Career History_Multi Sector ExperienceCFO_SB_Career History_Multi Sector Experience
CFO_SB_Career History_Multi Sector Experience
 
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
 
Top Rated Pune Call Girls Deccan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Deccan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Deccan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Deccan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
Top Rated Pune Call Girls Warje ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Warje ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Warje ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Warje ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
 
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
 
Escorts Service Cambridge Layout ☎ 7737669865☎ Book Your One night Stand (Ba...
Escorts Service Cambridge Layout  ☎ 7737669865☎ Book Your One night Stand (Ba...Escorts Service Cambridge Layout  ☎ 7737669865☎ Book Your One night Stand (Ba...
Escorts Service Cambridge Layout ☎ 7737669865☎ Book Your One night Stand (Ba...
 
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...
Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...
Sensual Moments: +91 9999965857 Independent Call Girls Paharganj Delhi {{ Mon...
 
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
 
OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理
 
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
 
Dubai Call Girls Starlet O525547819 Call Girls Dubai Showen Dating
Dubai Call Girls Starlet O525547819 Call Girls Dubai Showen DatingDubai Call Girls Starlet O525547819 Call Girls Dubai Showen Dating
Dubai Call Girls Starlet O525547819 Call Girls Dubai Showen Dating
 
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big BoodyDubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
 
CALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Nishatganj Lucknow best sexual service
 
Bur Dubai Call Girl Service #$# O56521286O Call Girls In Bur Dubai
Bur Dubai Call Girl Service #$# O56521286O Call Girls In Bur DubaiBur Dubai Call Girl Service #$# O56521286O Call Girls In Bur Dubai
Bur Dubai Call Girl Service #$# O56521286O Call Girls In Bur Dubai
 

Ertorelnotes

  • 1. Course Notes on From Entity-Relationship Schemas to Relational Schemas • The chapter deals with practical database design: 3 the construction of a relational schema from an E-R schema 3 this stage of database design is sometimes called “logical design”, besides concep- tual design (the construction of the E-R schema), physical design (the represen- tation of relations as files on disk and the choice of index structures) depending on the specific DBMS chosen and a given mix of application programs • CASE tools often 3 permit to build E-R schemas interactively 3 apply a version of the translation rules presented in this chapter • The relational model is poorer than the E-R model: the translation from an E-R schema to a relational schema entails a loss in the quality of the correspondence between the database schema and the appplication domain From E-R to Relational Schemas: Summary (1) Suppressing generalizations from ER schemas • Keeping the superentity • Keeping the subentity • Modeling by ordinary relationships (2) ER-to-relational mapping • Entities, weak entities • Relationships • Multi-valued attributes (3) Direct mapping of generalizations to relations 1 From Entity-Relationship to Relational Schemas, September 22, 2008 – 1 Suppressing Generalizations from ER Schemas • The semantics of generalization to be preserved: 3 mechanism of property inheritance 3 is-a relationship (subentities are also instances of the superentity class) • The solutions only approximate a faithful translation: 3 suppress subentity classes and express generalization semantics with the su- perclass 3 retain subentity classes only 3 model generalization as ordinary relationships 2 From Entity-Relationship to Relational Schemas, September 22, 2008 – 2
  • 2. Keeping the Superentity: Example Student Graduate Student Exchange Student SSN Name Major Advisor (1,1) Visits (0,1) (1,n)(1,n) ThesisTitle Option Professor University Student SSN Name Major Rank (0,1) ThesisTitle (0,1) Option (0,1) Advisor (1,1) Visits (0,1) (1,n)(1,n) Professor University (p,e) 3 • Transformation for the example: 3 suppress subentities Graduate Student and Exchange Student 3 propagate attributes and relationships of subentities to superentity Student, with optional participation (minimal cardinality of 0) 3 add a new discriminating attribute (Rank) with values that refer to the former subclasses (for example, GradStud and ExchStud) • Constraints are necessary in the transformed schema to preserve specific properties (attributes and relationships) of subentities in the initial schema: 3 all and only students with Rank = GradStud have an advising Professor and a Thesis Title 3 only Students with Rank = ExchStud may visit another University 3 all and only Students with Rank = ExchStud have an Option From Entity-Relationship to Relational Schemas, September 22, 2008 – 3 Transformation Keeping the Superentity • Properties of subentities are propagated to the superentity 3 attributes become optional 3 relationships become optional on the side of superentity • A new (discriminating) attribute is added to the superentity with cardinality (0,n) (1,n) (0,1) (1,1) for generalization partial, overlapping total, overlapping partial, exclusive total, exclusive • Constraints are added between the discriminating attribute and 3 attributes of subentities 3 participation of subentities in relationships 4 Keeping the Superentity: Evaluation • Drawbacks 3 optional attributes are introduced (null values) 3 operations concerning subentities now have to be expressed via the superen- tity: application programs become more complex 3 many constraints become explicit • Advantage: simple, always applicable 5 From Entity-Relationship to Relational Schemas, September 22, 2008 – 4
  • 3. Keeping the Subentities: Example Employee Secretary Engineer SSN Name Uses (1,n) Supervision (0,1) (0,n) (0,n) Skills (1,n) Speciality Word Processor Manager NbSuperv WorksOn (0,1) (1,n) Project Name Budget (t,e) 6 Keeping the Subentities: Translation of the Example Secretary Engineer Uses (1,n) (0,n) SSN Name Skills (1,n) SSN Name Speciality Word Processor Manager SSN Name NbSuperv WorksOn3 (0,n) Project Name Budget Supervision2 WorksOn1 (0,1) (0,1) (0,1) WorksOn2 (0,n) (0,n)(0,n) Supervision2 Supervision3 (0,1) (0,1) (0,n) (0,n) (0,1) Subordinate Supervisor 7 From Entity-Relationship to Relational Schemas, September 22, 2008 – 5 • Attributes of Employee (SSN, Name), and relationships WorksOn and Supervision are made explicit for each subentity • SSN is an identifier for each of Secretary, Engineer, and Manager • Constraint: the values of SSN must be unique across all three entity types Keeping the Subentities: Evaluation • Method: propagate to each subentity the attributes (and identifiers) and rela- tionship links of the superentity • Drawbacks 3 proliferation of essentially redundant attributes and relationships 3 application programs become more complex (operations on the superentity must now access all subentities) 3 inter-relation constraint (corresponding to identifier of superentity) • Only applicable to total-and-exclusive generalizations 8 • Exercise: 3 it is easy to transform any generalization into a total-and-exclusive generalization 3 this may lead to creating entities that were not naturally identified in the first place From Entity-Relationship to Relational Schemas, September 22, 2008 – 6
  • 4. Modeling with Relationships: Example Project HwProject SwProject SSN Name #Boards ManMonth Subcontract Contractor WorksOn (1,n) (1,n) Employee Name Budget (p,o) Uses (1,n) (0,n) Component 9 Modeling with Relationships: Translation of the Example Project HwProject SwProject SSN Name Uses (1,n) (0,n) #Boards ManMonth Component Subcontract Contractor WorksOn (1,n) (1,n) Employee Name Budget IsHwProj (0,1) (1,1) IsSwProj (0,1) (1,1) IsSubcont (0,1) (1,1) 10 From Entity-Relationship to Relational Schemas, September 22, 2008 – 7 Modeling with Relationships: Evaluation • New relationships are created (IsHwProj, ...): they are mandatory on subentities, optional on superentity • Former subentities have become weak entities with the former superentity as identifying entity • Old attributes and relationships are preserved • Drawbacks: 3 redundancy (the new relationships have the same meaning) 3 constraints are needed to express the type of generalization (totality, exclu- siveness) 3 some operations become more complex (e.g., insertion of a subtentity requires insertion of superentity) 11 ER-to-Relational Mapping • Derivation of a relational schema equivalent to a given ER schema without gen- eralizations • Versions of the translation are realized by CASE tools for database design, that produce relational schemas in the DDL of specific DBMSs • The basic translation can be realized with a few rules 12 From Entity-Relationship to Relational Schemas, September 22, 2008 – 8
  • 5. Company: ER Schema WorksFor (1,1) (4,n) Employee SSN Name FName MInit LName BDate Sex Salary Address Department Number Name Locations (1,n) /NoEmployees Controls Project Number Name Location WorksOn hours Supervision (1,n) (1,n) (1,n) (1,1) (1,1) (0,1) (0,1)(0,n) SuperviseeSupervisor Manages startDate Name Sex BDate Relationship DependOf (0,n) (1,1) Dependent 13 Company: Relational Representation Employee SSN MInit LName BDate Address Sex Salary SuperSSN DNo Department DNumber DName DMgr MgrStartDate DeptLocations DNumber DLocation Project PNumber PName PLocation DNumber WorksOn PNo ESSN Hours Dependent ESSN DependentName Sex BDate Relationship 14 From Entity-Relationship to Relational Schemas, September 22, 2008 – 9 • relations Employee, Department, Project represent entities (entity relations) • relation Employee also represents one-to-many relationships WorksFor and Supervision, relation Department represents one-to-one relationship Manages, relation Project rep- resents one-to-many relationship Controls • relation DeptLocations represents multivalued attribute Locations of entity Department • relation WorksOn represents the many-to-many relationship WorksOn between Em- ployee and Project (relationship relation) • relation Dependent merges relationship DependOf and weak entity Dependent Rule 1: Entity Type For each nonweak entity type E, create a relation R with • all simple attributes of E • the simple components of composite attributes of E (there is no notion of com- posite attribute in the relational model) • keys of R corresponding to identifiers of E Employee SSN FName MInit LName BDate Address Sex Salary Department DNumber DName Project PNumber PName PLocation 15 • More attributes will be added to R by subsequent rules to represent some of the 1-1 and 1-N relationships of the entity type represented by R • Relations like R are sometimes called entity relations From Entity-Relationship to Relational Schemas, September 22, 2008 – 10
  • 6. Rule 2: Weak Entity Type For each weak entity type F, create a relation R with • all simple attributes of F • simple components of composite attributes of F • as foreign key of R (i.e., with a referential integrity constraint), attribute(s) cor- responding to the primary key of the relation (produced by Rule 1) representing the entity identifying F • primary key of R = this foreign key + attributes of partial key of F Dependent ESSN DependentName Sex BDate Relationship 16 • Note that Rule 2 represents in relation R both the weak entity F and its relationship to the entity that contributes to identifying F • Remember that binary relationships R between E1 and E2 can be: 3 one-to-one (1-1) if the maximal cardinality of both E1 and E2 in R is 1 3 one-to-many (1-N) if the maximal cardinality of one of E1 and E2 in R is 1 and the other maximal cardinality is ¿ 1 3 many-to-many (M-N) if the maximal cardinality of both E1 and E2 in R is ¿ 1 • Basic ideas of the following rules for mapping relationships to relations: 3 1-1 and 1-N relationships can be represented by a foreign-key attribute (i.e., with referential integrity) in the relation representing the entity whose maximal cardinality in R is 1 (Rules 3 and 4) 3 each M-N relationship is mapped to a relation (Rule 5) 3 1-1 and 1-N relationships can also be mapped to a relation (by Rule 5) 3 each N-ary relationship is mapped to a relation (Rule 7) From Entity-Relationship to Relational Schemas, September 22, 2008 – 11 Rule 3: 1-1 Binary Relationship • Let R be a 1-1 relationship between entity types E1 and E2 (modeled as relations R1 and R2) • Choose R1 (or R2) to represent R; include in R1: 3 as foreign key (i.e., with referential integrity) the primary key of R2 3 the simple attributes and the simple components of the composite attributes of R • If the minimal cardinality of E1 in R is 0, there will be null values in the extension of R1 Department . . . DMgr MgrStartDate 17 • When choosing between R1 and R2 to represent relationship R, it is preferrable to choose the relation corresponding to an entity (E1 or E2) that is total in R (minimal cardinality = 1) in R: thos choice mimimizes null values in the chosen relation • Other possible representations for a 1-1 relationship: 3 R could also be represented by a relation, using Rule 5 (this solution is sometimes advocated to minimize null values, when the minimum cardinality of both E1 and E2 in R is 0) 3 R, E1, and E2 could all be represented in a single relation with two keys, each corresponding to the identifier of E1 and E2 From Entity-Relationship to Relational Schemas, September 22, 2008 – 12
  • 7. Rule 4: 1-N Binary Relationship • Let R be a 1-N relationship between entity types E1 and E2 (modeled as relations R1 and R2), with maximal cardinality of E1 = 1 and maximal cardinality of E2 = N • Include in R1 3 as foreign key (i.e., with referential integrity) the primary key of R2 3 the simple attributes and the simple components of the composite attributes of R Employee . . . SuperSSN DNo 18 Rule 5: M-N Binary Relationship • Let R be an M-N relationship between entity types E1 and E2 (modeled as relations R1 and R2) • Relationship R is represented as a relation R with: 3 as foreign keys (i.e., with referential integrity) the primary keys of R1 and R2 3 a composite primary key made of those two foreign keys 3 attributes corresponding to the simple attributes and to the simple compo- nents of the composite attributes of relationship R • This representation can also apply to 1-1 and 1-N relationships, thereby avoiding null values in relations • Relations like R are sometimes called relationships relations WorksOn ESSN PNo Hours 19 From Entity-Relationship to Relational Schemas, September 22, 2008 – 13 Rule 6: Multivalued Attribute • Let V be a multivalued attribute of an entity type E, and R1 be the relation representing E • Create a relation R with an attribute V and attribute(s) K for the primary key of R1 as foreign key of R (i.e., with referential integrity) • Primary key of R = V ∪ K • Problem: information about E (Departments) is split in 2 relations R and R1 DeptLocations DNumber DLocation 20 What Multivalued Relational Attributes Could Look Like Department DName DNumber DMgr {DLocations} 6 6 6 Department DName DNumber DMgr {DLocations} Research 5 333445555 {Bellaire,Sugarland,Houston} Administration 4 987654321 {Stafford} Headquarters 1 888665555 {Houston} • Multivalued attributes are not permitted in the relational model (“repeating groups” existed in its predecessors COBOL and CODASYL) • This would be a natural extension, but with more complex definitions for 3 the DML (algebra, calculi, SQL) 3 functional dependencies 21 From Entity-Relationship to Relational Schemas, September 22, 2008 – 14
  • 8. Rule 6 as Normalization of Multivalued Attributes into 1NF Department DName DNumber DMgr {DLocations} Research 5 333445555 {Bellaire,Sugarland,Houston} Administration 4 987654321 {Stafford} Headquarters 1 888665555 {Houston} ⇓ 1NF Normalization Department DName DNumber DMgr Research 5 333445555 Administration 4 987654321 Headquarters 1 888665555 DeptLocations DNumber DLocation 5 Bellaire 5 Sugarland 5 Houston 4 Stafford 1 Houston 22 Single-Relation Representation of Multivalued Attributes Department DName DNumber DMgr {DLocations} Research 5 333445555 {Bellaire,Sugarland,Houston} Administration 4 987654321 {Stafford} Headquarters 1 888665555 {Houston} ⇓ 1NF Normalization Department DName DNumber DLocation DMgr Research 5 Bellaire 333445555 Research 5 Sugarland 333445555 Research 5 Houston 333445555 Administration 4 Stafford 987654321 Headquarters 1 Houston 888665555 23 From Entity-Relationship to Relational Schemas, September 22, 2008 – 15 • The relational model, when it was defined in the early 1970’s, ruled out multival- ued attributes to mark a clear simplification in comparison to the previously existing models (COBOL, Codasyl) • Multivalued attributes are natural and useful, they were present as “repeating groups” in the pre-relational era, and are available in all object models • There is no good relational representation for E-R multivalued attributes: 3 the two-relation solution separates information that naturally goes together in the real world (the Location information is clearly a property of Departments) 3 the idea of the single-relation solution is to keep together pieces of information that concern the original entity ∗ the information about Department is represented in a single relation, the join of relations Department and DeptLocations in the two-relation representation ∗ this introduces redundancy (several tuples for each department with more than one location) ∗ the tuples of the join relation do not have a simple correspondence with thd real-world perception: a tuple represents information about one department AND one of its locations (not just about one department) Rule 7: N-ary Relationship (n > 2) Create a relation Rel that represents the n-ary relationship R, with • simple attributes of R and simple components of composite attributes of R • as foreign keys (i.e., with referential integrity), the primary keys of relations that represent the entity types of R • a composite primary key made of those foreign keys (except if an entity type E of R has maximum cardinality 1 in R, in which case the primary key of Rel is the primary key of the relation that represents E) 24 From Entity-Relationship to Relational Schemas, September 22, 2008 – 16
  • 9. N-ary Relationship: Example Supplier Supply (0,n) Project (0,n) Part (0,n) PartNo ProjNameSupName Quantity Supplier SupName . . . Project ProjName . . . Part PartNo . . . Supply SupName ProjName PartNo Quantity 25 • The composite key of relation Supply is made of SupName, ProjName, and PartNo • There is a referential integrity constraint from each of those attributes to the corre- sponding attribute in relations Supplier, Project, and Part From Entity-Relationship to Relational Schemas, September 22, 2008 – 17 Direct Relational Mapping of Generalization Secretary Technician SSN Name BirthDate TypingSpeed TechGrade Engineer EngType Employee (t,e) Generalization can be mapped directly to relations, by combining the previous rules for generalization elimination and E-R to relational mapping, with 3 solutions: • a relation for the superentity only • relations for subentities only • relations for both super- and subentities 26 Generalization: Single Relation for Superentity • For a generalization with subclasses {S1, . . . , Sm} and a superclass S where the attributes of S are {k, a1, . . . , am} and k is an identifier of S • Create a single relation L with 3 attributes {k, a1, . . . , am} ∪ {attributes of S1} ∪ . . . {attributes of Sn} ∪ {t} 3 primary key = k 3 t : new (“discriminating”) attribute, keeping track of subentities (JobType) 3 null values possible for subclass attributes (with constraints via t values) Employee SSN FName . . . TypingSpeed TechGrade EngType JobType 27 From Entity-Relationship to Relational Schemas, September 22, 2008 – 18
  • 10. Generalization : Relations for Subentities Only • For a generalization with subclasses {S1, . . . , Sm} and a superclass S where the attributes of S are {k, a1, . . . , am} and an identifier of S is k • Create a relation Li for each subclass Si with 3 attributes {attributes of Si} ∪ {k, a1, . . . , am} 3 primary key k, with unicity constraint across all Li’s Secretary SSN FName . . . TypingSpeed Technician SSN FName . . . TechGrade Engineer SSN FName . . . EngType 28 Generalization: Relations for Both Super- and Subentities • For a generalization with subclasses {S1, . . . , Sm} and a superclass S where the attributes of S are {k, a1, . . . , am} and an identifier of S is k 3 create a relation L for S with attributes {k, a1, . . . , am} and primary key k 3 create a relation Li for each Si with attributes {k} ∪ {attributes of Si} and primary key k Employee SSN FName MInit LName BirthDate Address Secretary SSN TypingSpeed Technician SSN TechGrade Engineer SSN EngType 29 From Entity-Relationship to Relational Schemas, September 22, 2008 – 19 Relations for Both Super- and Subentities: a Variant • Add a (redundant) view for each subclass, by joining the subclass relation with the superclass relation • Advantages 3 “materializing” attribute inheritance 3 saving a join in queries that involve inherited attributes Employee SSN FName MInit LName BirthDate Address Secretary SSN TypingSpeed Full-Secr SSN FName MInit LName BirthDate Address TypingSpeed 30 Entity Relationship versus Relational: Summary • ER schema is more compact (a connected graph) than relational schema (a collection of relations) ⇒ easier and more intuitive perception of information content • ER model has two main constructs: entities and relationships • Relational model only has relations, used as 3 “entity” relations (e.g., Employee, Department, Project, Dependent) 3 “relationship” relations (e.g., WorksOn) 3 “multivalued-attribute” relations (e.g., DeptLocations) 31 From Entity-Relationship to Relational Schemas, September 22, 2008 – 20
  • 11. Loss of Information in the ER-to-Relational Translation • Information loss relates to the quality of the correspondence between data model and the underlying real world 3 loss of precision: a single relational construct (relation) represents three ER constructs (entity, relationship, multivalued attribute) 3 the ER model was created after the relational model, to distinguish differ- ent types of relations (entity relations, relationship relations, multivalued attributes) • Good correspondence between ER schema and relational schema depends on 3 constraints (multiple referential integrity constraints, constraints for cardi- nalities) 3 documentation: informal description of the links between relations and concepts perceived in the real world 32 Issues for Database Design and Efficiency • 1-1 and 1-N relationship can be merged into the relation representing one of the participating entities or preserved as ”relationship” relations (Rules 3 and 4) • Pros of merging 3 fewer relations (simpler schemas) 3 fewer joins in queries • Cons of merging 3 relationships as independent constructs essentially disappear 3 more complexity from asymmetry of relationship representation 3 reduced extensibility (difficulty to get cardinalities right directly) • Representing multivalued attributes with two relations (Rule 6) is also a source of joins in queries 33 From Entity-Relationship to Relational Schemas, September 22, 2008 – 21