Database Lecture Notes Mapping ER Diagrams to Tables 2 Dr. Meg Murray

Slides:



Advertisements
Similar presentations
Database Design Chapter Five DATABASE CONCEPTS, 6th Edition
Advertisements

Data Modeling and the Entity-Relationship Model
Data Modeling and the Entity-Relationship Model
Data Modeling and the Entity-Relationship Model Chapter Four DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
(wrapping up from last week)
Data Modeling and the Entity-Relationship Model
Database Design Chapter Five DATABASE CONCEPTS, 6th Edition
Entity-Relationship Model
Data Modeling and the Entity-Relationship Model
Data Modeling and the Entity-Relationship Model
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 6.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the ER Model.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 9.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke Database Processing Chapter 6 Transforming Data.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 COS 346 Day 10.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 COS 346 Day 8.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 COS 346 Day 7.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 7.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming Data Models into Database.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 8.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 6.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 6 Database Design Using Entity- Relationship Models.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
Data Modeling and the Entity-Relationship Model Chapter Four DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Database Design Chapter Five DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
Database Design Chapter Five DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Entity-Relationship Model
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming ER Models into Database.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming ER Models into Database.
Mapping ERM to relational database
Database Design.  Define a table for each entity  Give the table the same name as the entity  Make the primary key the same as the identifier of the.
Data Modeling and the Entity-Relationship Model Chapter Four DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall 5-1 Chapter Objectives Learn how to transform E-R data models into relational.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Six: Transforming Data Models into Database Designs.
Database Design IST210 Class Lecture
+ Data Modeling (wrapping up from last week). + Homework Review Exercise 4.32 – Develop a data model of a genealogical diagram. Model only biological.
Data Modeling IST210 Class Lecture.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming Data Models into Database.
CS 370 Database Systems Lecture 9 The Relational model.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
1 A Demo of Logical Database Design. 2 Aim of the demo To develop an understanding of the logical view of data and the importance of the relational model.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Database Design Chapter Five DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming Data Models into Database.
Gegevens Analyse Les 5: van ERD naar DSD.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming Data Models into Database.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Five: Data Modeling with the Entity-Relationship.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Six: Transforming Data Models into Database Designs.
Database Processing: David M. Kroenke’s Chapter Five:
Chapter 4: Logical Database Design and the Relational Model
CSIS 115 Database Design and Applications for Business
Transforming Data Models
Chapter 4: Part B Logical Database Design and the Relational Model
Database Design Chapter Five DATABASE CONCEPTS, 4th Edition
Requirements Become the E-R Data Model
CSIS 115 Database Design and Applications for Business
CSIS 115 Database Design and Applications for Business
Database Applications
Database Processing: David M. Kroenke’s Chapter Five:
Database Processing: David M. Kroenke’s Chapter Six:
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Database Processing: David M. Kroenke’s Chapter Six:
Database Processing: David M. Kroenke’s Chapter Five:
Database Processing: David M. Kroenke’s Chapter Six:
Database Processing: David M. Kroenke’s Chapter Six:
Presentation transcript:

Database Lecture Notes Mapping ER Diagrams to Tables 2 Dr. Meg Murray

Mapping Relationships What are the 2 categories of relationships?

Mapping Strong Entity Relationships

Representing Relationships 1:1 Relationships The maximum cardinality determines how a relationship is represented 1:1 relationship –The key from one relation is placed in the other as a foreign key –It does not matter which table receives the foreign key usually –Should be placed in the most frequently accessed entity –If one side is optional, Foreign Key goes on the OPTIONAL side KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Relationships 1:1 Relationship Example KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Create Relationships: 1:1 Notes Either design will work – no parent, no child Minimum cardinality considerations may be important: –O-M will require a different design than M-O –One design is often preferable –THE FOREIGN KEY SHOULD BE PLACED IN THE OPTIONAL SIDE Make the foreign key an alternate key KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Relationships 1:N Relationships Like a 1:1 relationship, a 1:N relationship is saved by placing the key from one table into another as a foreign key However, in a 1:N the foreign key always goes into the many-side of the relationship –The 1 side is called the parent –The N side is called the child KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Relationships 1:N Relationship Example KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Create Relationships: N:M Strong Entity Relationships In an N:M strong entity relationship there is no place for the foreign key in either table: –A COMPANY may supply many PARTs –A PART may be supplied by many COMPANYs KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Create Relationships: N:M Strong Entity Relationships N:M strong entity will always be mapped to two 1:N relationships –This table is called an intersection table The key of the intersection table is a composite key of both primary keys from the related entities –Each table’s primary key becomes a foreign key linking back to that table KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Create Relationships: N:M Strong Entity Relationships COMPANY_PART_INT (CompanyName, PartNumber) KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Relationships N :M Relationship Example 2 KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Mapping Weak Entity Relationships

Representing Weak Entities ID-dependent –must add primary key of the parent entity Not ID-dependent –use the same techniques as for strong entities KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Four Relationships for Weak Entities Representing N:M Relationships –We just discussed this Association Relationships Multivalued Attributes Archtype/Instance Relationships KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

ID-Dependent ID-dependent –The primary key of the strong entity becomes part of the composite primary key of the weak entity –Except in cases of surrogate keys, N:M, Association relationships and Multivalued Attributes map to ID-dependent relationships

Representing Weak Entities – ID-dependent Example KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Relationships Using ID-Dependent Entities: Association Relationships An intersection table: –Holds the relationships between two strong entities in an N:M relationship –Contains only the primary keys of the two entities: As a composite primary key As foreign keys An association table: –Has all the characteristics of an intersection table –PLUS it has one or more columns of attributes specific to the associations of the other two entities KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Relationships Association Relationships When an intersection table has columns beyond those in the primary key, the relationship is called an association relationship KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

ID-Dependent Association Relationship Example 2 QUOTATION (CompanyName, PartNumber, Price) KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Relationships Using ID-Dependent Entities: Multivalued Attributes As a data model As a set of tables KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Relationships Using ID-Dependent Entities: Archetype/Instance Pattern As a data model As a set of tables KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Weak Entities Non ID-dependent Not ID-dependent –The primary key of the strong entity is placed as an attribute [foreign key] in the weak entity Not used in the primary key Special case for surrogate keys –An alternate key in the strong entity is placed as an attribute [foreign key] in the weak entity

Relationships Using Weak Entities: Non ID-dependent As a data model As a set of tables Note where the Foreign Key is placed – not part of the primary key KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Note when using Surrogate Keys Surrogate keys in an ID-dependent relationship take special consideration because the surrogate key has no ‘human’ meaning One way to handle this is to put the identifier of the parent as a foreign key in the child BUT NOT as part of the primary key –Use a surrogate key for the child as well –This means you will have a Weak relationship but not an ID dependent one KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Entities: Tables with Surrogate Key: CUSTOMER Example Surrogate Keys -CustomerID (id) -FirstName -LastName -Street -City -State -Zip CUSTOMER -PhoneNumber(id) -Customer(id) -PhoneType PHONES SurrogateKey CustomerID FirstName LastName Street City State Zip PHONES -PhoneNumber -PhoneType -Customer(FK)

Other Examples 6-27

Representing Relationships Supertype/Subtype Relationships The identifier of the supertype becomes the primary key and the foreign key of each subtype Note the supertype and subtypes all have the same primary key KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Subtype Relationships Example 2 As a data model As a set of tables KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Representing Relationships Recursive Relationships A recursive relationship is a relationship that a relation has with itself. Recursive relationships adhere to the same rules as the binary relationships. –1:1 and 1:M relationships are saved using foreign keys –M:N relationships are saved by creating an intersecting relation KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Recursive Relationships: 1:1 Recursive Relationships As a data model As a table KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Recursive Relationships: 1:N Recursive Relationships As a data model As a table KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Recursive Relationships: N:M Recursive Relationships As a data model As a set of tables KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Mixed Entity Relationships: The Line-Item Pattern Common Sales Order {shopping cart} Problem –Create a separate table to represent each line for each item ordered

Mixed Entity Relationships: The Line-Item Pattern As a data model KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Mixed Entity Relationships: The Line-Item Pattern As a set of tables KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Heather Sweeney Designs: Developing a Database Design Heather Sweeney Designs will be used as on ongoing example throughout Chapters 4, 5, 6 and 7. –Heather Sweeney is an interior designer who specializes in home kitchen design –She offers a variety of free seminars at home shows, kitchen and appliance stores, and other public locations –She earns revenue by selling books and videos that instruct people on kitchen design –She also offers custom-design consulting services KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Heather Sweeney Designs: Final Data Model KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Heather Sweeney Designs: Database Design KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall

Heather Sweeney Designs: Database Design Schema SEMINAR (SeminarID, Date, Time, Location, Title) CUSTOMER ( Address, Name, Phone, Street, City, State, Zip) SEMINAR_CUSTOMER (SeminarID, Address) CONTACT ( Address, Date, ContactNumber, ContactType, SeminarID) PRODUCT (ProductNumber, Description, UnitPrice, QuantityOnHand) INVOICE (InvoiceNumber, Date, PaymentType, SubTotal, Tax, Total, Address) LINE_ITEM (InvoiceNumber, LineNumber, Quantity, UnitPrice, Total, ProductNumber) KROENKE and AUER - DATABASE CONCEPTS (3 rd Edition) © 2008 Pearson Prentice Hall