1 Relational Model and Translating ER into Relational.

Slides:



Advertisements
Similar presentations
Database Management Systems Chapter 3 The Relational Data Model (I) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Advertisements

Tallahassee, Florida, 2014 COP4710 Database Systems Relational Model Fall 2014.
CSCI 305 – Fall 2013 The Entity-Relationship Model Based on Slides by Prof. Brian King.
Information Systems Chapter 4 Relational Databases Modelling.
1 Convert E/R to Relation May 18, Entity Set -> Relation Relation: Beers(name, manf) Beers name manf.
Databases : Relational Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Entity-Relationship Model
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
1 Lecture 04 Entity/Relationship Modelling. 2 Outline E/R model (Chapter 5) From E/R diagrams to relational schemas (Chapter 5) Constraints in SQL (Chapter.
Lecture #2 October 5 th, 2000 Conceptual Modeling Administration: –HW1 available –Details on projects –Exam date –XML comment.
The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.
From ER Diagrams to the Relational Model Rose-Hulman Institute of Technology Curt Clifton.
1 Announcement Recitation time  Before midterm: 6-7pm, by Earl Wagner  After midterm: 5-6pm, by Yi Qiao Newsgroup safe to subscribe  Will not cause.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
1 Lecture 3: Database Modeling (continued) April 5, 2002.
Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections Assignment 1 due. Personal Letter of Introduction.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman.
Winter 2002Arthur Keller – CS 1803–1 Schedule Today: Jan. 10 (TH) u Relational Model, Functional Dependencies. u Read Sections Jan. 15 (T) u Normal.
Lecture 9: Conceptual Database Design January 27 th, 2003.
Multiplicity in E/R Diagrams
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
CS411 Database Systems Kazuhiro Minami
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
E/R Diagrams and Functional Dependencies. Modeling Subclasses The world is inherently hierarchical. Some entities are special cases of others We need.
Lecture 08: E/R Diagrams and Functional Dependencies.
Lecture 2: E/R Diagrams and the Relational Model Thursday, January 4, 2001.
1 Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the.
1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007.
Entity-Relationship Model
 Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.
Data Modeling Translating E-R Diagrams to Relations
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
CS 405G: Introduction to Database Systems Lecture 5: Logical Design by Relational Model Instructor: Chen Qian.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Instructor: Jinze Liu Fall Phases of Database Design u Conceptual design begins with the collection of requirements and results needed from the.
Entity-Relationship Model E/R Diagrams Converting E/R Diagrams to Relations.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Functional Dependencies.
CS 405G: Introduction to Database Systems Relations.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
CS422 Principles of Database Systems From ER to Relations Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture notes.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
Introduction to Database Systems, CS420
Lecture 5: Conceptual Database Design
Entity-Relationship Model
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
BBM 471 – Database Management Systems
COP4710 Database Systems Relational Model.
Cushing, Keller, UlmanJudy Cushing
CPSC-310 Database Systems
CS 440 Database Management Systems
Instructor: Zhe He Department of Computer Science
CPSC-310 Database Systems
From E/R Diagrams to Relational Schema
Lecture 4: Database Modeling (continued)
Lecture 2: Database Modeling (end) The Relational Data Model
Lecture 06 Data Modeling: E/R Diagrams
name category name price makes Company Product stockprice buys employs
Lecture 5: The Relational Data Model
The Relational Data Model
CS4433 Database Systems Relational Model.
CS 405G Introduction to Database Systems
CS 505: Intermediate Topics to Database Systems
Lecture 08: E/R Diagrams and Functional Dependencies
CS 405G: Introduction to Database Systems
Presentation transcript:

1 Relational Model and Translating ER into Relational

2 Lecture Outline Relational model Translating from ER to relational model

3 Motivations & comparison of ER with relational model...

4 Database Modeling & Implementation Database Model (E/R, ODL) Database Model (E/R, ODL) Ideas Physical storage Physical storage Diagrams (E/R) Tables: column names: attributes rows: tuples Complex file organization and index structures. Relational Schema Relational Schema

5 ER Model vs. Relational Model Both are used to model data ER model has many concepts –entities, relations, attributes, etc. –well-suited for capturing the app. requirements –not well-suited for computer implementation –(does not even have operations on its structures) Relational model –has just a single concept: relation –world is represented with a collection of tables –well-suited for efficient manipulations on computers

6 The basics of the relational model...

7 An Example of a Relation Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi tuples Attribute names Table name Products:

8 Domains Each attribute has a type Must be atomic type (why? see later) Called domain Examples: –Integer –String –Real –…

9 Schemas vs. instances (very important, make sure you know the difference)

10 Schemas The Schema of a Relation: –Relation name plus attribute names –E.g. Product(Name, Price, Category, Manufacturer) –In practice we add the domain for each attribute The Schema of a Database –A set of relation schemas –E.g. Product(Name, Price, Category, Manufacturer), Vendor(Name, Address, Phone),

11 Instances Relational schema = R(A1,…,Ak): Instance = relation with k attributes (of “type” R) –values of corresponding domains Database schema = R1(…), R2(…), …, Rn(…) Instance = n relations, of types R1, R2,..., Rn

12 Example Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi Relational schema:Product(Name, Price, Category, Manufacturer) Instance:

13 Annother Example Students:Takes: Courses: Three relational schemas here + three relational instances One database schema + one database instance

14 Updates The database maintains a current database state (that is, a database instance). Updates to the data (that is, the database instance) 1) add a tuple 2) delete a tuple 3) modify an attribute in a tuple Updates to the data happen very frequently. Updates to the schema: relatively rare. Rather painful. Why?

15 Schemas and Instances Analogy with programming languages: –Schema = type –Instance = value Important distinction: –Database Schema = stable over long periods of time –Database Instance = changes constantly, as data is inserted/updated/deleted

16 How should we talk about relations (that is, represent them)? Will skip this in the class You can read for fun

17 Two Mathematical Definitions of Relations Relation as Cartesian product Tuple = element of string x int x string x string E.g. t = (gizmo, 19, gadgets, GizmoWorks) Relation = subset of string x int x string x string Order in the tuple is important ! –(gizmo, 19, gadgets, GizmoWorks) –(gizmo, 19, GizmoWorks, gadgets) No attributes

18 Relation as a set of functions Fix the set of attributes –A={name, price, category, manufacturer} A tuple = function t:A Domains Relation = set of tuples E.g. Order in a tuple is not important Attribute names are important {name gizmo, price 19, category gadgets, manufacturer gizmoWorks} {name gizmo, price 19, category gadgets, manufacturer gizmoWorks}

19 Two Definitions of Relations We will switch back and forth between these two: –Positional tuples, without attribute names –Relational schemas with attribute names

20 Now the fun part: translating from ER to relational model

21 Translating ER Diagram to Rel. Design Basic cases –entity set E = relation with attributes of E –relationship R = relation with attributes being keys of related entity sets + attributes of R Special cases –combining two relations –translating weak entity sets –translating is-a relationships and subclasses

22 address namessn Person buys makes employs Company Product namecategory Stock price name price An Example

23 Basic cases...

24 Entity Sets to Relations Product namecategory price Product: Name Category Price gizmo gadgets $19.99

25 Relationships to Relations makes Company Product namecategory Stock price name Relation Makes (watch out for attribute name conflicts) Product-name Product-Category Company-name Starting-year gizmo gadgets gizmoWorks 1963 Start Year price

26 Relationship to Relation: Another Example DrinkersBeers Likes Likes(drinker, beer) Favorite Favorite(drinker, beer) Married husband wife Married(husband, wife) name addr name manf Buddies 1 2 Buddies(name1, name2)

27 Special cases: 1) many-one relations 2) weak entity sets 3) is-a cases

28 Combining Two Relations makes Company Product namecategory Stock price name No need for Makes. Just modify Product: name category price StartYear companyName gizmo gadgets gizmoWorks Start Year price

29 Combining Relations It is OK to combine the relation for an entity-set E with the relation R for a many-one relationship from E to another entity set. Example: Drinkers(name, addr) and Favorite(drinker, beer) combine to make Drinker1(name, addr, favoriteBeer).

30 Risk with Many-Many Relationships Combining Drinkers with Likes would be a mistake. It leads to redundancy, as: name addr beer Sally 123 Maple Bud Sally 123 Maple Miller Redundancy

31 Handling Weak Entity Sets UniversityTeam affiliation numbersportname Relation Team: Sport Number Affiliated University mud wrestling 15 Montezuma State U. - need all the attributes that contribute to the key of Team - don’t need a separate relation for Affiliation. (why ?)

32 Handling Weak Entity Sets Relation for a weak entity set must include attributes for its complete key (including those belonging to other entity sets), as well as its own, nonkey attributes. A supporting (double-diamond) relationship is redundant and yields no relation.

33 Another Example LoginsHostsAt name Hosts(hostName) Logins(loginName, hostName, time) At(loginName, hostName, hostName2) Must be the same time At becomes part of Logins

34 Translating Subclass Entities Product Educational Product Software Product Educ-software Product ageGroup topic Platforms required memory Educational-method isa

35 Option #1: the OO Approach 4 tables: each object can only belong to a single table Product(name, price, category, manufacturer) EducationalProduct( name, price, category, manufacturer, ageGroup, topic) SoftwareProduct( name, price, category, manufacturer, platforms, requiredMemory) EducationalSoftwareProduct( name, price, category, manufacturer, ageGroup, topic, platforms, requiredMemory) All names are distinct

36 Option #2: the E/R Approach Product(name, price, category, manufacturer) EducationalProduct( name, ageGroup, topic) SoftwareProduct( name, platforms, requiredMemory) No need for a relation EducationalSoftwareProduct Unless, it has a specialized attribute: EducationalSoftwareProduct(name, educational-method) Same name may appear in several relations

37 Option #3: The Null Value Approach Have one table: Product ( name, price, manufacturer, age-group, topic, platforms, required-memory, educational-method) Some values in the table will be NULL, meaning that the attribute not make sense for the specific product. Too many meanings for NULL

38 Translating Subclass Entities: The Rules Three approaches: 1.Object-oriented : each entity belongs to exactly one class; create a relation for each class, with all its attributes. 2.E/R style : create one relation for each subclass, with only the key attribute(s) and attributes attached to that E.S.; entity represented in all relations to whose subclass/E.S. it belongs. 3.Use nulls : create one relation; entities have null in attributes that don’t belong to them.

39 Example Beers Ales isa name manf color

40 Object-Oriented namemanf BudAnheuser-Busch Beers name manfcolor Summerbrew Pete’sdark Ales

41 E/R Style namemanf Bud Anheuser-Busch Summerbrew Pete’s Beers name color Summerbrew dark Ales

42 Using Nulls namemanf color Bud Anheuser-Busch NULL Summerbrew Pete’s dark Beers

43 Comparisons O-O approach good for queries like “find the color of ales made by Pete’s.” –Just look in Ales relation. E/R approach good for queries like “find all beers (including ales) made by Pete’s.” –Just look in Beers relation. Using nulls saves space unless there are lots of attributes that are usually null.

44 Translation Review Basic cases –entity to table, relation to table –selecting attributes based on keys Special cases –many-one relation can be merged –merging many-many is dangerous –translating weak entity sets –translating isa hierarchy 3 choices, with trade-offs