Download presentation
Presentation is loading. Please wait.
Published byGordon Matthews Modified over 9 years ago
1
CS34311 Translating ER Schema to Relational Model
2
cs34312 Basic Mapping So Far Simple algorithm covers base case Each entity type = separate relation Each relationship type = separate relation
3
cs34313 Simple Algorithm: Example 3 PRIMARY KEY (Part) = PRIMARY KEY (Contains) = FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber) FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber) Part (pName, pNumber) Contains (superPart, subPart, quantity)
4
cs34314 Next Let’s consider constraints Let’s reduce number of relations
5
cs34315 Refinement for Simple Mapping Primary Key for R’ is defined as: If the maximum cardinality of any Ei is 1, primary key for R’ = primary key for Ei
6
cs34316 Simple Algorithm: Example 3 PRIMARY KEY (Part) = PRIMARY KEY (Contains) = FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber) FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber) Part (pName, pNumber) Contains (superPart, subPart, quantity)
7
cs34317 Decreasing the Number of Relations Technique 1 If the relationship type R contains an entity type, say E, whose maximum cardinality is 1, then R may be represented as attributes of E.
8
cs34318 Example 1 If R contains entity type E whose max. cardinality is 1, then R may be represented as attributes of E.
9
cs34319 Example 1 Student (sNumber, sName, advisor, years) Professor (pNumber, pName) PRIMARY KEY (Student) = PRIMARY KEY (Professor) = FOREIGN KEY Student (advisor) REFERENCES Professor (pNumber) Question: Will Student.advisor attribute ever be NULL ? Answer: No ! So add the NOT NULL constraint.
10
cs343110 Example 2 Person (pNumber, pName, works-in, years) Dept (dNumber, dName) PRIMARY KEY (Person) = PRIMARY KEY (Dept) = FOREIGN KEY Person (worksin) REFERENCES Dept (dNumber) What about NULL attributes ? Worksin and years may be null for a person
11
cs343111 Remember the Simple Algorithm: Example 3 PRIMARY KEY (Part) = PRIMARY KEY (Contains) = PRIMARY KEY (Contains) = FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber) FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber) Part (pName, pNumber) Contains (superPart, subPart, quantity)
12
cs343112 Example 3: The Reduced Case. Part (pNumber, pname, hasSuperPart, quantity) PRIMARY KEY (Part) = FOREIGN KEY Part (hasSuperPart) REFERENCES Part (pNumber) Note: hasSuperPart indicates the superpart of a part, and it may be null
13
cs343113 Decreasing the Number of Relations Summary of Technique 1 If the relationship type R contains an entity type, say E, whose maximum cardinality is 1, then R may be represented as attributes of E. If cardinality of E is (1, 1), then add “not null”
14
cs343114 Decreasing Number of Relations Technique 2: Even more radical : If relationship type R between E1 and E2 is “one-to-one” [1:1], and the cardinality of E1 or of E2 is (1, 1), then we can combine everything into one 1 relation.
15
cs343115 Decreasing the Number of Relations Technique 2 - Method Details Let us assume the cardinality of E1 in R is (1, 1). Then we create one relation for entity E2 And, we make all attributes of E1 and of R to become attributes of E2.
16
cs343116 Example 1 Student-BIG (sNumber, sName, pNumber, pName, years) PRIMARY KEY (Student) = ANY OTHER KEY ? CANDIDATE KEY (Student) = Note: pNumber, pName, and years can be null for students with no advisor
17
cs343117 Example 2 Student (sNumber, sName, pNumber, pName, years) PRIMARY KEY (Student) = CANDIDATE KEY (Student) = Note: pNumber cannot be null for any student.
18
cs343118 Decreasing Number of Relations Technique 2 For one-to-one relationship R with E cardinality (1, 1), then combine everything into 1 relation. While very compact, semantically may not be clearest choice. Therefore, not always recommended !
19
cs343119 ER Model: Complex Attributes Composite Attribute: address Student sNamesumer sAge statestreet address city Composite attribute in ER Include an attribute for every component of the composite attribute.
20
cs343120 ER Model: Complex Attributes Multivalued Attribute: major Mapping Multi-valued attribute in ER: Need separate relation for multi-valued attribute. Identify appropriate attributes, keys & foreign key constraints.
21
cs343121 Multi-valued attribute Student (sNumber, sName, sAge, street, city, state) PRIMARY KEY (Student) = StudentMajor (sNumber, major) PRIMARY KEY (StudentMajor) = FOREIGN KEY StudentMajor (sNumber) REFERENCES Student (sNumber)
22
cs343122 Summary Simple algorithms covers base case Refinements: Reduce number of relations Refinements: Consider constraints (not NULL) Consider other ER constructs like complex and multi-valued attributes
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.