Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006.

Similar presentations


Presentation on theme: "Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006."— Presentation transcript:

1 Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006

2 Lecture 6© CIS 4301 - Spring 20062 Sample Movie Database Movies Stars Stars-in title year length filmType name address MN Convert Relationship type into relation (Stars-in) whose attributes are the attribute(s) of Relationship type (if any), and the keys of the involved entity Sets What are the keys of the new relations Stars-in?

3 Lecture 6© CIS 4301 - Spring 20063 Conversion Problems  Resulting Relations Movies(title,year,length,filmType,studioName) StarsIn(title,year,starName) Stars(name,address) Shall we combine Movies and StarsIn? StarsIn many-many from Movies to Stars Combined relation: (title,year,length,filmType,studioName,starName) Good design?

4 Lecture 6© CIS 4301 - Spring 20064 Combining Relations For many-one relationships, not necessary to create separate table for relationship type Ex.: many-one relationship Owns between Movies and Studios Current guidelines would lead to: Movies (title, year, length, filmType) Owns (title, year, studioName) Studios(name, address) Since Owns is many-one, attributes in Owns are uniquely determined by key for Movies

5 Lecture 6© CIS 4301 - Spring 20065 “Optimization” Fold primary key attribute(s) of the relation representing the “1” part into relation representing the “many” part Owns(title, year, studioName) Movies(title, year, length, filmType, studioName) Studios(name, address)

6 Lecture 6© CIS 4301 - Spring 20066 One-one Relationship Set MovieExecs Studios Is-CEO-of name address salary name address

7 Lecture 6© CIS 4301 - Spring 20067 One-one Relationship Set MovieExecs Studios Is-CEO-of nameaddressceoName Fox Paramount Disney Hollywood Buena Vista Big Lee Eisner Studios nameaddresssalary Eisner Lee Big Newport Beach Brentwood Beverly Hills 2.8M 1M 3.8M MovieExecs SmithMalibu 0.9M name address salary name address

8 Lecture 6© CIS 4301 - Spring 20068 Converting a 4-Way Relationship Movies Studios Stars Contracts Producing Studio Studio of Star

9 Lecture 6© CIS 4301 - Spring 20069 Converting a 4-Way Relationship Create relation Contracts Just like when we converted multi-way relationships into multiple binary relationships Contracts has the following schema From Stars the key “starname” From Movies the key consisting of “title” and “year” From Studios the key “studioOfStar” From Studios the key “producingStudio” Why? Contracts (starName,title,year,studioOfStar, producingStudio)

10 Lecture 6© CIS 4301 - Spring 200610 Weak Entity Sets Must do three things differently: Relation for weak entity must not only include attributes of weak entity but also key attributes of other entities helping to form the key for weak entity Supporting relationship from weak entity to other entities that help provide key for weak entity need not be converted Any relation representing a relationship in which weak entity appears must use as key for weak entity all of its key attributes including those of other entities

11 Lecture 6© CIS 4301 - Spring 200611 Weak Entity Sets Studios address name Unit-of Crews number 1N Studios(name, addr) Crews(number, studioName) Unit-of(number, studioName, name) Studios(name, addr) Crews(number, studioName) (Optimization Step: Dispense with Unit-of ) Renamed for clarity

12 Lecture 6© CIS 4301 - Spring 200612 Conversion Rules If W is a weak entity set, construct for W a relation whose schema consists of: All attributes of W All attributes of supporting relationships for W For each supporting relationship of W, all key attributes of the entity that is connected to W via the supporting relationship

13 Lecture 6© CIS 4301 - Spring 200613 Converting Subclass Structures Several conversion strategies Approach 1: Create relation for each entity Attributes of the entity set and key attributes from the root (superclass) entity No relation created for ISA relationship See Sec. 3.3.2 and 3.3.3 for alternatives

14 Lecture 6© CIS 4301 - Spring 200614 Converting an ISA-Hierarchy Movies titleyearlengthfilmType Cartoons Murder Mysteries weapon Voices N M ISA

15 Lecture 6© CIS 4301 - Spring 200615 Equivalent Relational Schema Movies(title, year,length, filmType) MurderMysteries(title, year, weapon) Cartoons(title, year)

16 Lecture 6© CIS 4301 - Spring 200616 Exercise Convert the following E/R diagram into an equivalent relational database schema Courses Lab Courses isa computer allocation room number GivenBy Depts name chair


Download ppt "Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006."

Similar presentations


Ads by Google