Database Principles ER to RDM Mapping. Database Principles Mapping from ER to Relational Data Model the next phase Exercise: Give me some suggestions.

Slides:



Advertisements
Similar presentations
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Advertisements

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Chapter 3 : Relational Model
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Model Fall 2014.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
ENTITY RELATIONSHIP MODELLING
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
Database Principles SQL 2. Database Principles Aggregate Queries SQL has 5 built-in “column functions” called aggregate functions. –min(): Returns the.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
Murali Mani The Relational Model. Murali Mani Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example.
Chapter 14 Getting to First Base: Introduction to Database Concepts.
Database Principles Relational Algebra. Database Principles What is Relational Algebra? It is a language in which we can ask questions (query) of a database.
Information Resources Management February 13, 2001.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Database Design Concepts Lecture 7 Introduction to E:R Modelling Identifying Entities.
Venn Diagrams Database Principles.
Database Principles Relational Database Design I.
Data Modeling Using the Entity-Relationship Model
1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.
Dr. Mohamed Osman Hegaz1 Conceptual data base design: The conceptual models: The Entity Relationship Model.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model.
RAJIKA TANDON DATABASES CSE 781 – Database Management Systems Instructor: Dr. A. Goel.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
Using Relational Databases and SQL John Hurley Department of Computer Science California State University, Los Angeles Lecture 3: Joins Part I.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 1 ©Akhilesh Bajaj, 2000, 2002, 2003, All.
Copyright © 2005 Ed Lance Fundamentals of Relational Database Design By Ed Lance.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Entity-Relationship (ER) Modelling ER modelling - Identify entities - Identify relationships - Construct ER diagram - Collect attributes for entities &
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
The Relational Model1 ER-to-Relational Mapping and Views.
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.
In this session, you will learn to: Map an ER diagram to a table Objectives.
Database Principles Relational Database Design II.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Object Oriented Database By Ashish Kaul References from Professor Lee’s presentations and the Web.
Data Modeling Using the Entity-Relationship (ER) Data Model.
Relational Data Model DeSiaMore Powered by DeSiaMore.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 2 © Akhilesh Bajaj, 2000, 2002, 2003, 2004,
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh Part-2.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
Jennifer Widom Relational Databases The Relational Model.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
1 Relational Algebra and SQL. 2 Relational Query Languages Languages for describing queries on a relational database Relational AlgebraRelational Algebra.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Year 12 > 13 Applied GCE ICT Unit 7 Using Database Software.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Logical DB Design: ER to Relational
The Relational Model.
RELATION.
Entity-Relationship Model
Relational Algebra Chapter 4, Part A
Translation of ER-diagram into Relational Schema
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
From ER to Relational Model
Relational Databases The Relational Model.
Relational Databases The Relational Model.
LECTURE 3: Relational Algebra
Database Modeling using Entity Relationship Model (E-R Model)
Database Management system
Presentation transcript:

Database Principles ER to RDM Mapping

Database Principles Mapping from ER to Relational Data Model the next phase Exercise: Give me some suggestions on what this mapping would look like.

Database Principles Relational Data Model Models all information stored in a database as a collection of related mathematical structures called relations. Suppose –Students = {s 1, s 2, s 3, …, s n } and – Courses = {c 1, c 2, c 3, …, c m } The Cartesian Product of these two sets is: –Students x Courses = { (s i, c j ) | s i ε Students, c j ε Courses } remember this word

Database Principles Student x Course Grid: (s 1,c 1 ) (s 2,c 3 ) (s n,c m )

Database Principles Relational Data Model A relation is a subset of a Cartesian Product. Enrollment = {(s 1, c 2 ), (s 2, c 3 ), (s 2, c 2 ) } Enrollment is a subset of Students x Courses Exercise: Suppose Student is a set of patients and Professor is a set of doctors. Give several examples of relations that are subsets of Student x Professor. Exercise: Go through the exercise of asking a student you do not know for examples of useful relations and identity their corresponding Cartesian Products.

Database Principles Enrollment NOTE: Points inside the ellipse correspond to real- world information. Points outside the ellipse do not correspond to any real- world event and we call them noise. Enrollment noise points

Database Principles Exercise: A tournament of local soccer teams is run as a double round-robin tournament. What does this mean? Describe the difference between such a tournament and one we could describe as a cartesian product tournament. Work in pairs. If you know what double round-robin means find someone who doesn’t and explain it to them. Then answer the question. Draw a simple ER for this example

Database Principles Relational Data Model A table containing a list of all suppliers - an ID, name and address for each – is called Supplier. This table is a subset of the Cartesian Product so mathematically it too is a relation. Of course, the only rows in the table are the useful tuples of the Cartesian Product, those that really correspond to some supplier. ID SName SAddress Supplier SupplierIDs x SupplierNames x SupplierAddresses

Database Principles Exercise: Consider the previous round-robin tournament. What happens if we have an extra line in the Plays table? This line is noise!! It makes the entire table useless. Why? Plays A C 2 1 noise Rule to Follow: Database tables should contain no noise.

Database Principles Table Parts A table has two parts – intension and extension Intension: what the table is “intended” to model. In essence, the table name and the name of each of its columns; otherwise known as the table schema. Extension: A list of all possible rows of the table; both presently existing and what might exist in the future or has existed in the past. ID SName SAddress Supplier Table Schema extension

Database Principles Notational Correspondence: ER Entity Relationship Attribute Key Attributes Instance RDM Table/Relation Schema Column/Attribute Primary Key Row/Tuple Exercise: The title of this lecture is “ER-to-RDM Mapping“. The above notational correspondence leads one to think that this mapping is quite straight forward. What is the one thing that is not straight forward about this implied mapping?

Database Principles ER-to-RDM Mapping, Rule 1: Each entity is mapped to a table schema with the same columns as the entity has attributes. CARDHOLDER borrowerid b_name b_addr b_status loan_limit borrowerid b_name b_addr b_status loan_limit CARDHOLDER pk maps to

Database Principles Rule 1 (cont) The actual mapping is to syntax in SQL which can be used to create the table described by our schematic. Create table CARDHOLDER ( borrowerid int not null primary key, b_name varchar(10), b_addr varchar(10), b_status char(6), loan_limit int ) borrowerid b_name b_addr b_status loan_limit CARDHOLDER pk its an integer can never be null is the primary key of the table

Database Principles ER-to-RDM Mapping, Rule 2a: If a relationship has no (1,1) participation number pair then it too is mapped to a table schema. The table schema consists of: –The key attributes of all entities participating in the relationship –All attributes of the relationship. The primary key of the new table consists of all the key attributes of the entities participating in the relationship and any relationship attribute identifies as part of the key.

Database Principles ER-to-RDM Mapping, Rule 2a:

Database Principles ER-to-RDM Mapping, Rule 2b: If a relationship has a (1,1) participation number pair then it is not mapped to a table schema. Instead, the table schema corresponding to the entity with the (1,1) pair takes on additional columns: –The keys of all other entities participating in the relationship are migrated to the entity table schema –The attributes of the relationship itself are migrated to the entity able schema. The primary key of the entity table schema does not change.

Database Principles ER-to-RDM Mapping, Rule 2b: stays the same BOOK

Database Principles Review of Mapping Complexity: Relationships model real-world associations. In a database, these associations can be modeled in one of two ways: –By a table of their own; the table key is a combination of entity keys –Within one of the participating entity tables.

Database Principles Weak Entity ER-to-RDM Mapping, Rule 2b: Relationships that attach to a weak entity always follow Rule 2b. This is because the weak entity always has a (1,1) pair. However, the key to the table schema corresponding to the weak entity consists of the attributes in the weak entity key.

Database Principles IS_A ER-to-RDM Mapping, Rule 2b: IS_A relationships always follow Rule 2b because the sub-entity always has a (1,1) pair.

Database Principles Considering (0,1) as (1,1) What if a relationship with a (0,1) pair were mapped to a RDM under the assumption that the (0,1) pair is really (1,1)? becomes (1,1) disappears

Database Principles Are These Models Equivalent? Suppose two copies exist – one on loan and one not. There can only be one row in Borrows that contains the value “qt-23.4_c1”. Why? So there can only be one possible value that can go into the borrowerid column of the row in Copy that contains “qt-2.34_c1” since this book is not on loan there is no borrowerid or l_date

Database Principles Considering (1,1) as (1,n): Suppose you are a database designer and are told that every project is managed by precisely one employee. But you ask, “Might it be possible in the future to have more than one manager for a project?”, and the answer is “Yes”.

Database Principles Considering (1,1) as (1,n): x

Database Principles Considering (1,1) as (1,n): The advantage of the second model is that the relationship will be mapped to its own table. This is not true in the first case. If you create the ManagedBy table from the very beginning it will be there when you need it. A little more work up front saves a lot of work later on. You can show off later on by saying “It will only take a second”, come back in 15 minutes and say “the database can now handle multiple project managers” because it always could even when it didn’t need to. If you are working as a consultant you can bill for 8 hours even though it didn’t take any time at all.

Database Principles Library to Relational Data Model In the next series of slides we map the Library ER Model to a Relational Data Model

Database Principles Cardholder to RDM NOTE: As an entity, Cardholder maps to a table with all its attributes as table columns. The key to Cardholder becomes the primary key to the table Cardholder. Since Cardholder has no (1,1) participation number pairs, no new columns are added to the table. not (1,1)

Database Principles Book to RDM NOTE: As an entity, Book maps to a table with all its attributes as table columns. The key to Book becomes the primary key to the table Book. Since Book has no (1,1) participation number pairs, no new columns are added to the table. not (1,1)

Database Principles Reserves to RDM NOTE: As a relationship with no (1,1) pair, reserves is mapped to a table whose columns include the keys to the entities participating in the reserves relationship together with the attributes of reserves.

Database Principles Borrows to RDM NOTE: As a relationship with no (1,1) pair, borrows is mapped to a table whose columns include the keys to the entities participating in the borrows relationship together with the attributes of borrows.

Database Principles Copy to RDM NOTE: As an entity with a (1,1) participation number pair, Copy is mapped to a table that contains all the Copy attributes and the key attributes of the other entities (Book) in the relationship where Copy has a (1,1) pair. The relationship with the (1,1) pair is not mapped to a table.

Database Principles Putting it all Together:

Database Principles Exercise: ER 2 RDM Person, Office, Professor Student, Course, Has_taught CrsSection, Enrolled_in