Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Database Principles ER to RDM Mapping. Database Principles Mapping from ER to Relational Data Model the next phase Exercise: Give me some suggestions."— Presentation transcript:

1 Database Principles ER to RDM Mapping

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

3 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

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

5 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.

6 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

7 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

8 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

9 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.

10 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

11 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?

12 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

13 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

14 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.

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

16 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.

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

18 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.

19 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.

20 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.

21 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

22 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

23 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”.

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

25 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.

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

27 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)

28 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)

29 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.

30 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.

31 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.

32 Database Principles Putting it all Together:

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


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

Similar presentations


Ads by Google