Download presentation
Presentation is loading. Please wait.
Published byLesley Patterson Modified over 8 years ago
1
Converting ER/EER to logical schema; physical design issues 1
2
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS Mapping Regular Entities to Relations Simple attributes: E-R attributes map directly onto the relation Composite attributes: Use only their simple, component attributes Multivalued Attribute: Becomes a separate relation with a foreign key taken from the superior entity 2
3
(a) CUSTOMER entity type with simple attributes Figure 4-8 Mapping a regular entity (b) CUSTOMER relation 3 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
4
4 (a) CUSTOMER entity type with composite attribute Figure 4-9 Mapping a composite attribute (b) CUSTOMER relation with address detail 4 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
5
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 5 Figure 4-10 Mapping an entity with a multivalued attribute One–to–many relationship between original entity and new relation (a) Multivalued attribute becomes a separate relation with foreign key (b)
6
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Weak Entities Becomes a separate relation with a foreign key taken from the superior entity Primary key composed of: Partial identifier of weak entity Primary key of identifying relation (strong entity) 6
7
7 Figure 4-11 Example of mapping a weak entity a) Weak entity DEPENDENT 7 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
8
8 NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity Foreign key Composite primary key Figure 4-11 Example of mapping a weak entity (cont.) b) Relations resulting from weak entity 8 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
9
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Binary Relationships One-to-Many–Primary key on the one side becomes a foreign key on the many side Many-to-Many–Create a new relation with the primary keys of the two entities as its primary key One-to-One–Primary key on mandatory side becomes a foreign key on optional side 9
10
10 Figure 4-12 Example of mapping a 1:M relationship a) Relationship between customers and orders Note the mandatory one b) Mapping the relationship Again, no null value in the foreign key…this is because of the mandatory minimum cardinality. Foreign key 10 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
11
11 Figure 4-13 Example of mapping an M:N relationship a) Completes relationship (M:N) The Completes relationship will need to become a separate relation. 11 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
12
12 new intersection relation Foreign key Composite primary key Figure 4-13 Example of mapping an M:N relationship (cont.) b) Three resulting relations 12 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
13
13 Figure 4-14 Example of mapping a binary 1:1 relationship a) In charge relationship (1:1) Often in 1:1 relationships, one direction is optional 13 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
14
14 b) Resulting relations Figure 4-14 Example of mapping a binary 1:1 relationship (cont.) Foreign key goes in the relation on the optional side, matching the primary key on the mandatory side 14 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
15
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Associative Entities Identifier Not Assigned Default primary key for the association relation is composed of the primary keys of the two entities (as in M:N relationship) Identifier Assigned It is natural and familiar to end-users Default identifier may not be unique 15
16
16 Figure 4-15 Example of mapping an associative entity a) An associative entity 16 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
17
17 Figure 4-15 Example of mapping an associative entity (cont.) b) Three resulting relations Composite primary key formed from the two foreign keys 17 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
18
18 Figure 4-16 Example of mapping an associative entity with an identifier a) SHIPMENT associative entity 18 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
19
19 Figure 4-16 Example of mapping an associative entity with an identifier (cont.) b) Three resulting relations Primary key differs from foreign keys 19 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
20
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Unary Relationships One-to-Many–Recursive foreign key in the same relation Many-to-Many–Two relations: One for the entity type One for an associative relation in which the primary key has two attributes, both taken from the primary key of the entity 20
21
21 Figure 4-17 Mapping a unary 1:N relationship (a) EMPLOYEE entity with unary relationship (b) EMPLOYEE relation with recursive foreign key 21 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
22
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 22 Figure 4-18 Mapping a unary M:N relationship (a) Bill-of-materials relationships (M:N) (b) ITEM and COMPONENT relations
23
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Ternary (and n-ary) Relationships One relation for each entity and one for the associative entity Associative entity has foreign keys to each entity in the relationship 23
24
24 Figure 4-19 Mapping a ternary relationship a) PATIENT TREATMENT Ternary relationship with associative entity 24 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
25
25 b) Mapping the ternary relationship PATIENT TREATMENT Remember that the primary key MUST be unique. Figure 4-19 Mapping a ternary relationship (cont.) This is why treatment date and time are included in the composite primary key. But this makes a very cumbersome key… It would be better to create a surrogate key like Treatment#. 25 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
26
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall TRANSFORMING EER DIAGRAMS INTO RELATIONS (CONT.) Mapping Supertype/Subtype Relationships One relation for supertype and for each subtype Supertype attributes (including identifier and subtype discriminator) go into supertype relation Subtype attributes go into each subtype; primary key of supertype relation also becomes primary key of subtype relation 1:1 relationship established between supertype and each subtype, with supertype as primary table 26
27
27 Figure 4-20 Supertype/subtype relationships 27 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
28
28 Figure 4-21 Mapping supertype/subtype relationships to relations These are implemented as one-to-one relationships. 28 Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
29
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE © 2013 Pearson Education, Inc. Publishing as Prentice Hall 29 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi
30
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall PHYSICAL DATABASE DESIGN Purpose–translate the logical description of data into the technical specifications for storing and retrieving data Goal–create a design for storing data that will provide adequate performance and ensure database integrity, security, and recoverability 30
31
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall DESIGNING FIELDS Field: smallest unit of application data recognized by system software Field design Choosing data type Coding, compression, encryption Controlling data integrity 31
32
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall CHOOSING DATA TYPES 32
33
33 Figure 5-2 Example of a code look-up table (Pine Valley Furniture Company) Code saves space, but costs an additional lookup to obtain actual value 33 Chapter 5 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
34
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall HANDLING MISSING DATA Substitute an estimate of the missing value (e.g., using a formula) Construct a report listing missing values In programs, ignore missing data unless the value is significant (sensitivity testing) 34 Triggers can be used to perform these operations.
35
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall DENORMALIZATION Transforming normalized relations into non-normalized physical record specifications Benefits: Can improve performance (speed) by reducing number of table lookups (i.e. reduce number of necessary join queries) Costs (due to data duplication) Wasted storage space Data integrity/consistency threats Common denormalization opportunities One-to-one relationship (Fig. 5-3) Many-to-many relationship with non-key attributes (associative entity) (Fig. 5-4) Reference data (1:N relationship where 1-side has data not used in any other relationship) (Fig. 5-5) 35
36
36 Figure 5-3 A possible denormalization situation: two entities with one- to-one relationship 36 Chapter 5 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
37
37 Figure 5-4 A possible denormalization situation: a many-to-many relationship with nonkey attributes Extra table access required Null description possible 37 Chapter 5 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
38
38 Figure 5-5 A possible denormalization situation: reference data Extra table access required Data duplication 38 Chapter 5 © 2013 Pearson Education, Inc. Publishing as Prentice Hall
39
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall DENORMALIZE WITH CAUTION Denormalization can Increase chance of errors and inconsistencies Reintroduce anomalies Force reprogramming when business rules change Perhaps other methods could be used to improve performance of joins Organization of tables in the database (file organization and clustering) Proper query design and optimization 39
40
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall PARTITIONING Horizontal Partitioning: Distributing the rows of a logical relation into several separate tables Useful for situations where different users need access to different rows Three types: Key Range Partitioning, Hash Partitioning, or Composite Partitioning Vertical Partitioning: Distributing the columns of a logical relation into several separate physical tables Useful for situations where different users need access to different columns The primary key must be repeated in each file Combinations of Horizontal and Vertical 40
41
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall PARTITIONING PROS AND CONS Advantages of Partitioning: Efficiency: Records used together are grouped together Local optimization: Each partition can be optimized for performance Security: data not relevant to users are segregated Recovery and uptime: smaller files take less time to back up Load balancing: Partitions stored on different disks, reduces contention Disadvantages of Partitioning: Inconsistent access speed: Slow retrievals across partitions Complexity: Non-transparent partitioning Extra space or update time: Duplicate data; access from multiple partitions 41
42
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall RULES FOR USING INDEXES 1. Use on larger tables 2. Index the primary key of each table 3. Index search fields (fields frequently in WHERE clause) 4. Fields in SQL ORDER BY and GROUP BY commands 5. When there are >100 values but not when there are 100 values but not when there are <30 values 42
43
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall RULES FOR USING INDEXES (CONT.) 6. Avoid use of indexes for fields with long values; perhaps compress values first 7. If key to index is used to determine location of record, use surrogate (like sequence number) to allow even spread in storage area 8. DBMS may have limit on number of indexes per table and number of bytes per indexed field(s) 9. Be careful of indexing attributes with null values; many DBMSs will not recognize null values in an index search 43
44
Chapter 4 © 2013 Pearson Education, Inc. Publishing as Prentice Hall RULES FOR USING INDEXES (CONT.) 6. Avoid use of indexes for fields with long values; perhaps compress values first 7. If key to index is used to determine location of record, use surrogate (like sequence number) to allow even spread in storage area 8. DBMS may have limit on number of indexes per table and number of bytes per indexed field(s) 9. Be careful of indexing attributes with null values; many DBMSs will not recognize null values in an index search 44
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.