280 likes | 295 Views
Learn the design methodology for creating efficient and effective databases, including one-to-one and many-to-many relationship considerations, handling null values, and entity subtypes.
E N D
Chapter 6 Database Design 2: Design Methodology Spring 2006 Concepts of Database Management, 5th Edition, Pratt & Adamski
Exercise #4 0 • Due: Feb 22 for full credit, March 1 for 50% credit • Points: 20 points • Pratt & Adamski (End of Chapters 5 & 6) • Assignments must have cover sheet with your name. • Chapter 5 [pp 170-171]: Answer questions 1, 2, 3 for Premiere Products and questions 2, 4 for Henry Books. Omit 4NF, answer the questions for 3NF. • Chapter 6 pp [223-224]: Answer questions 2, 4 for Premiere Products and questions 1, 2, 3 for Henry Books. Turn in ERD and copies of new tables and attributes. (Alternatively, use DBDL.) Concepts of Database Management, 5th Edition, Pratt & Adamski
One-to-One [1:1] Relationship Considerations • 1:N [maximum cardinality] relationships are the standard. Let’s start by examining how to treat 1:1 relationships • Implementing a one-to-one relationship by simply including the primary key of each table as a foreign key in the other table • A problem is that there is no guarantee that the information will match Concepts of Database Management, 5th Edition, Pratt & Adamski
1:1 Relationship Considerations (con’t) • One possible solution is to create a single table. OK? • Although workable, two features are not particularly attractive: • Combines columns of two different entities into a single table. Violates “single theme” table notion. • If possible for one entity to exist without the other, then this would cause an insertion/deletion anomaly Concepts of Database Management, 5th Edition, Pratt & Adamski
1:1 Relationship Considerations (con’t) • Better solution!! • Create two separate tables for Customers and Sales Reps and to include the primary key of one of them as a foreign key in the other • This foreign key would also be designated as an alternate key Concepts of Database Management, 5th Edition, Pratt & Adamski
1:1 Relationship Considerations Figure 6.20 (6.25) (4th Ed.) Include primary key of each table as foreign key in the other. OVERKILL! Concepts of Database Management, 5th Edition, Pratt & Adamski
1:1 Relationship Considerations Figure 6.22 Implemented in a single table. Possible Anomalies? Add new Rep: Tyler Harris? What if Tyler has no customers? Concepts of Database Management, 5th Edition, Pratt & Adamski
1:1 Relationship Considerations Figure 6.23 1:1 relationship implemented by including primary key of one table as foreign key in ONLY the other. Concepts of Database Management, 5th Edition, Pratt & Adamski
Many-to-Many [N:M] Relationship Considerations • Complex issues arise when more than two entities are related in a N:M relationship [binary relationship] • Many-to-many-to-many [N:M:P] relationship – involves multiple entities [tertiary or higher relationships] • Crucial issue in making the determination between a single many-to-many-to-many relationship and two (or three) many-to-many relationships is the independence of each entity. • Birth [Mother, Father, Child] One vs. multiple relations • Parent:Child vs. Mother:Father:Child Concepts of Database Management, 5th Edition, Pratt & Adamski
Future N:M:P slide • Birth [Mother, Father, Child] vs. … Mom Dad Baby Concepts of Database Management, 5th Edition, Pratt & Adamski
Null Values • Null - a special value (not a blank) • Null - actually represents the absence of a value in a field (undefined) • Nulls - used when a value is either unknown or not applicable [“UNK” or “N/A”] • NULL is a SQL reserved word: SELECT * FROM EMP WHERE PHONENO=NULL; Concepts of Database Management, 5th Edition, Pratt & Adamski
Table Split to Avoid Null Values Figure 6.27 Nulls are absence of values Concepts of Database Management, 5th Edition, Pratt & Adamski
Entity Subtypes • Entity subtype – table that is a subtype of another table • Incomplete category – records that do not fall into the subtype • Complete categories – all records fall into the categories Concepts of Database Management, 5th Edition, Pratt & Adamski
Entity Subtypes Incomplete CategoriesFigure 6.29 Concepts of Database Management, 5th Edition, Pratt & Adamski
Student Table Split into Subtypes Helps to Avoid NullsFigure 6.31 Concepts of Database Management, 5th Edition, Pratt & Adamski
Two Entity SubtypesComplete CategoriesFigure 6.33 Concepts of Database Management, 5th Edition, Pratt & Adamski
Entity-Relationship Model[Chen: Extended ERDs] • Various ERD methodologies use different symbols to represent data; non-standardized notation • E.g., Entities are drawn as rectangles • Relationships are drawn as diamondswith lines connecting the entities involved in relationships Concepts of Database Management, 5th Edition, Pratt & Adamski
ERD 1:N RelationshipDiamond SymbolFigure 6.34 Often 1:N is placed inside the Diamond symbol Concepts of Database Management, 5th Edition, Pratt & Adamski
ERD 1:N Relationship Crow’s Foot Symbol Figure 6.42 Concepts of Database Management, 5th Edition, Pratt & Adamski
One-to-Many Relationship (with Property/Attribute Ovals) Figure 6.37 Concepts of Database Management, 5th Edition, Pratt & Adamski
Many-to-Many RelationshipLetter Designators (m:n)Figure 6.35 Concepts of Database Management, 5th Edition, Pratt & Adamski
N:M Relationship with Attributes Figure 6.38 Concepts of Database Management, 5th Edition, Pratt & Adamski
Composite Entity • Composite entity - an entity that exists to implement a many-to-many relationship • A.k.a., Intersection Table or Association Table • Essentially both an entity and a relationship • Represented in an E-R diagram by a diamond within a rectangle Concepts of Database Management, 5th Edition, Pratt & Adamski
Composite Entity [OrderLine] Figure 6.39 Attribute Ovals Concepts of Database Management, 5th Edition, Pratt & Adamski
Complete ER Diagram Figure 6.40 Concepts of Database Management, 5th Edition, Pratt & Adamski
Maximum & MinimumCardinality • Maximum Cardinality – the most items that can appear on either side of a relationship • Minimum Cardinality – the least number of items that must be included in a relationship • An entity in a relationship with minimum cardinality of zero plays an optional role in the relationship • An entity with a minimum cardinality of one plays a mandatory role in the relationship Concepts of Database Management, 5th Edition, Pratt & Adamski
Representing Cardinality Figure 6.43 Concepts of Database Management, 5th Edition, Pratt & Adamski
Summary • Database design is a two-part process (logical & physical) of determining an appropriate database structure to satisfy a given set of requirements • Entity-relationship (ER) model is a method of representing the structure of a database using an ER diagram (ERD): Examples: ERDx & IDEF1X • A database design is represented in a language called Database Design Language (DDL) • One-to-One [1:1] and One-to-Many [1:N] relationships require attention to primary keys • N:M relationships require Composite tables Concepts of Database Management, 5th Edition, Pratt & Adamski