Download presentation
Presentation is loading. Please wait.
Published byNoreen Manning Modified over 8 years ago
1
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations
2
2 A Relation is a Table namemanf WinterbrewPete’s Bud LiteAnheuser-Busch Beers Attributes (column headers) Tuples (rows)
3
3 Schemas uRelation schema = relation name and attribute list. wOptionally: types of attributes. wExample: Beers(name, manf) or Beers(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: Beers(name, manf) Beers name manf
7
7 Relationship -> Relation 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)
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: Drinkers(name, addr) and Favorite(drinker, beer) combine to make Drinker1(name, addr, favBeer).
9
9 Risk with Many-Many Relationships uCombining Drinkers with Likes would be a mistake. It leads to redundancy, as: name addr beer Sally 123 Maple Bud Sally 123 Maple Miller 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 Beers Ales isa name manf color
14
14 Object-Oriented namemanf BudAnheuser-Busch Beers name manfcolor Summerbrew Pete’sdark Ales Good for queries like “find the color of ales made by Pete’s.”
15
15 E/R Style namemanf Bud Anheuser-Busch Summerbrew Pete’s Beers name color Summerbrew dark Ales Good for queries like “find all beers (including ales) made by Pete’s.”
16
16 Using Nulls namemanf color Bud Anheuser-Busch NULL Summerbrew Pete’s dark Beers Saves space unless there are lots of attributes that are usually NULL.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.