Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman.

Similar presentations


Presentation on theme: "1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman."— Presentation transcript:

1 1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman

2 2 A Relation is a Table namemanf SnickersM&M/Mars TwizzlersHershey Candies Attributes (column headers) Tuples (rows)

3 3 Schemas uRelation schema = relation name and attribute list. wOptionally: types of attributes. wExample: Candies(name, manf) or Candies(name: string, manf: string) uDatabase = collection of relations. uDatabase schema = set of all relation schemas in the database.

4 4 Why Relations? uVery simple model. uOften matches how we think about data. uAbstract model that underlies SQL, the most important database language today.

5 5 From E/R Diagrams to Relations uEntity set -> relation. wAttributes -> attributes. uRelationships -> relations whose attributes are only: wThe keys of the connected entity sets. wAttributes of the relationship itself.

6 6 Entity Set -> Relation Relation: Candies(name, manf) Candies name manf

7 7 Relationship -> Relation Con- sumers Candies Likes Likes(consumer, candy) Favorite Favorite(consumer, candy) Married husband wife Married(husband, wife) name addr name manf Buddies 1 2 Buddies(name1, name2)

8 8 Combining Relations uOK to combine into one relation: 1.The relation for an entity-set E 2.The relations for many-one relationships of which E is the “many.” uExample: Consumers(name, addr) and Favorite(consumer, candy) combine to make Consumer1(name, addr, favCandy).

9 9 Risk with Many-Many Relationships uCombining Consumers with Likes would be a mistake. It leads to redundancy, as: name addr candy Sally 123 Maple Twizzler Sally 123 Maple Kitkat Redundancy

10 10 Handling Weak Entity Sets uRelation 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. uA supporting relationship is redundant and yields no relation (unless it has attributes).

11 11 Example LoginsHostsAt name Hosts(hostName, location) Logins(loginName, hostName, billTo) At(loginName, hostName, hostName2) Must be the same billTo At becomes part of Logins location

12 12 Subclasses: Three Approaches 1.Object-oriented : One relation per subset of subclasses, with all relevant attributes. 2.Use nulls : One relation; entities have NULL in attributes that don’t belong to them. 3.E/R style : One relation for each subclass: wKey attribute(s). wAttributes of that subclass.

13 13 Example Candies Choc- olates isa name manf color

14 14 Object-Oriented namemanf TwizzlerHershey Candies name manfcolor SnickersM&M/Mars light Chocolates Good for queries like “find the color of chocolate candies made by M&M/Mars.”

15 15 E/R Style namemanf Twizzler Hershey Snickers M&M/Mars Candies name color Snickers light Chocolates Good for queries like “find all candies (including chocolates) made by M&M/Mars.”

16 16 Using Nulls namemanf color Twizzler Hershey NULL Snickers M&M/Mars dark Candies Saves space unless there are lots of attributes that are usually NULL.


Download ppt "1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman."

Similar presentations


Ads by Google