FEN 2014-03-231 Mapping from Class Diagram (Domain Model) to Relational Model Table Design.

Slides:



Advertisements
Similar presentations
Banking Business Scenario
Advertisements

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Relational Database Design Via ER Modelling
Assignment Design Methodology A structured approach that uses procedures, techniques, tools, and documentation aids to support and facilitate the.
Mapping ER to Relational Model
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the.
Text-Book Chapters (7 and 8) Entity-Relationship Model
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Database Management Systems I Alex Coman, Winter 2006 Entity-Relationship.
Methodology Logical Database Design for the Relational Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
APPENDIX C DESIGNING DATABASES
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Entity-Relationship Model
Chapter 91 ER & EER to Relational Mapping. Chapter 92 ER to Relational Mapping Step 1: For each regular entity type E in the ER schema, create a relation.
ER- and EER-to-Relational Mapping
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
1 DATABASE TECHNOLOGIES BUS Abdou Illia, Fall 2007 (Week 3, Tuesday 9/4/2007)
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
Web-Enabled Decision Support Systems
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
FEN  Concepts and terminology  Operations (relational algebra)  Integrity constraints The relational model.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
Copyright © 2003 Addison-Wesley Sree Nilakanta. Copyright © 2003 Addison-Wesley Developing Relational Models What is the relational model and what is.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
In this session, you will learn to: Map an ER diagram to a table Objectives.
Mapping from conceptual model (EER-M)
FEN NOEA/IT - Databases/ODB1 ODB – Object DataBases Object-Oriented – Fundamental Concepts UML and EE/R OO and Relational Databases Introduction.
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
CS263 Lecture 5: Logical Database Design Can express the structure of a relation by a Tuple, a shorthand notation Name of the relation is followed (in.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
ER/EER to Relational Mapping Chapter 9. STEP 1 ENTITY TYPE E (non weak) -> NEW RELATION T RELATION T: – includes all simple attributes (non composite,
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
ER-TO-RELATIONAL MODEL MAPPING CONTENT SOURCES: ELAMSARI AND NAVATHE, FUNDAMENTALS OF DATABASE MANAGEMENT SYSTEMS.
Data modeling Process. Copyright © CIST 2 Definition What is data modeling? –Identify the real world data that must be stored on the database –Design.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
Transforming ER models to relational schemas
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Introduction to Database Systems
CS3431: C-Term Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
FEN Introduction to the database field: The development process Seminar: Introduction to relational databases Development process: Analyse.
Database Design I IST 210: Organization of Data IST2101.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Chapter 2: Entity-Relationship Model
Relational Database Design by ER- and EER-to- Relational Mapping
Entity-Relationship Model
ER- and EER-to-Relational
© 2011 Pearson Education, Inc. Publishing as Prentice Hall
Session 2 Welcome: The seventh learning sequence
Relational Database Design by ER- and EER-to-Relational Mapping
Presentation transcript:

FEN Mapping from Class Diagram (Domain Model) to Relational Model Table Design

Implementation Strategy How are objects stored in a relational database? We need to store: Identity State Class Structures: generalisation association aggregation 2FEN prgVar1 prgVar2

Mapping: Identity, State (and Class) Each class is mapped onto a table (relation): Class name is used as table name All simple-value attributes are transferred to the table (a column) A primary key (id) is added to the table For each attribute consider: Domain (type) NULLs Uniqueness For composite attributes only the components are added For list attributes (multi value) a new table holding the primary key and the value of the list attribute is created FEN

The structures can cause new attributes Semantic of the class diagram must be preserved There are more than one possible mapping for a structure Mapping object-relationships: Associations and aggregations: One-to-one One-to-many Many-to-many Class structure: Inheritance: Three different solutions 4FEN Mapping: Structure

Structure: many-to-many (*..* or n:m) CustomerAccount Account Customer CustomerIDCPR Name Address Jens Andersen Søndergade Oda Nielsen Algade Pia Schrøder Bispensgade 27 AccountIdAccountnoBalancetype checkkonto lån checkkonto Account AccountNo Balance Type Customer CPR Name Address 0:m 1:m 5FEN New table with the two primary keys as foreign keys CustomerIdAccountID

Account AccountIDAccountNoBalanceType CustomerId checkkonto lån checkkonto 5 Two alternatives 1.As many to many. 2.The key from the one-side is added as an attribute to the many-side as a foreign key Account AccountNo Balance Date Customer CPR Name Address 1 1:m 6FEN Structure: one-to-many (1..* or 1:n)

Account AccountIDAccountNoBalanceType CustomerId checkkonto lån checkkonto 5 Account AccountNo Balance Date Customer CPR Name Address 1 1 7FEN Structure: one-to-one (1..1 or 1:1) Two alternatives 1.As many to many. 2.The key from one of the sides is added as an attribute to the other side as a foreign key.

The key from one of the sides is added as an attribute to the other side as a foreign key. But at which side? Account AccountNo Balance Date Customer CPR Name Address 1 1 8FEN Structure: one-to-one (1..1 or 1:1) Customer CusIDCPRnameaddresse accountId Jens AndersenSøndergade Oda NielsenAlgade Pia SchrøderBispensgade

On which side should the foreign key be included? Choose the side that minimises NULL values Account AccountNo Balance Date Customer CPR Name Address 1 1 9FEN Structure: one-to-one (1..1 or 1:1) Person Car 11 On which side should the foreign key be included?

Minimise NULL values: - are most cars assigned to a specific person? - do most persons have car to their disposal? What if the company is a car rental company? 10FEN Structure: one-to-one (1..1 or 1:1) Person Car 11 On which side should the foreign key be included?

11 Three kinds multiplicities: One-to-one (1-1): One person is associated with one car One-to-many (1-n): One person may be associated with several cars, but one car is only associated with one person Many-to-many (n-m): One person may be associated with several cars, and one car may be associated with many persons Person Car 11 PersonCar 1* Person Car ** Mapping: Structure FEN

12 Three kinds multiplicities: One-to-one (1-1): Include the primary key from one of the sides on the other side (minimise NULLs). One-to-many (1-n): Include the primary key from the one- side on the many-side. Many-to-many (n-m): Create a new table with the primary keys from both sides as foreign keys. The combination of the to foreign keys becomes primary key in the new table. Person Car 11 PersonCar 1* Person Car ** Mapping: Object Structure FEN

Three Approaches for Transformation 1.Create a table for the super-class and a table for each subclass (“The Nice Way”). 2.Create tables only for the subclasses (“Pull-Down”). 3.Create a table only for the super-class (“Pull-Up”). 13FEN Mapping: Class Structure – Inheritance

14 accIDaccNodateaccType checkAcc loan checkAcc accIDintRatenextBook 10, , Account accIDamountpaymentdateForPay CheckAccount Loan Conceptually attractive. Clear and simple, traceability is good, and the design may always be used. Easy to maintain. Accessing objects requires joins. Mapping: Class Structure – Inheritance (1: “The Nice Way”) FEN

CheckAccount accDaccNodate intRate nextBook , , FEN Mapping: Class Structure – Inheritance (2: “Pull-Down”)) No table for the super-class. Easy to retrieve all information if the type is known. Works best, if there are few attributes in the super-class. Does not work, if objects may belong to more than one subclass, or if there exists objects of the superclass Code duplication

No tables for subclasses. Easy access. Works best if there are few attributes in the subclasses. Problems with null values 16FEN Mapping: Class Structure – Inheritance (3: “Pull-Up”))

17 Summary: Domain Model Mapping to RDB Each domain class is mapped to a table: Attributes, keys, data types, NULLs? Primary key is added (or chosen). Associations and aggregations are represented by foreign key references: 1-1: Include the primary key of the one-side as foreign key on the other side (minimise NULLs). 1-n: Include the primary key of the one-side as foreign key on the n-side. n-m: Create a new table with both sides primary key as foreign keys. Generalisation: choose one of these designs: 1.Each class (both super- and subclasses) is mapped to a table. The general and special parts of an object are connected by the same primary key. The superclass may have added a type flag (preferable, but may be expensive in joins). 2.Only subclasses are mapped to tables that include the attributes from the superclass (no overlap allowed!). 3.Only the superclass is mapped to a table that includes a type flag and all attributes from the subclasses. All attributes from irrelevant subclasses are NULL (may cause many NULLs). FEN

Exercise Design a database for a library with this domain model. I.e. Define relational table schemas. Add some relevant attributes, consider if nulls are allowed. On the association Reservation there are some attributes (date, the state, etc.). FEN