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 you to added to the CS mailing list Send all course related questions there for timely response (unless privacy needed)
24
Embed
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.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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 you to added to the CS
mailing list Send all course related questions there for
timely response (unless privacy needed)
2
The Relational Data Model
TablesSchemas
Conversion from E/R to Relations
3
A Relation is a Table
name manfWinterbrew Pete’sBud Lite Anheuser-
BuschBeers
Attributes(columnheaders)
Tuples(rows)
4
Schemas
• Relation schema = relation name and attribute list. Optionally: types of attributes. Example: Beers(name, manf) or
Beers(name: string, manf: string)• Database = collection of relations.• Database schema = set of all
relation schemas in the database.
5
Why Relations?
• Very simple model.• Often matches how we think about
data.• Abstract model that underlies SQL,
the most important database language today.
6
From E/R Diagrams to Relations
• Entity set -> relation. Attributes -> attributes.
• Relationships -> relations whose attributes are only: The keys of the connected entity sets. Attributes of the relationship itself.
7
Entity Set -> Relation
Relation: Beers(name, manf)
Beers
name manf
8
Relationship -> Relation
Drinkers BeersLikes
Likes(drinker, beer)Favorite
Favorite(drinker, beer)
Married
husband
wife
Married(husband, wife)
name addr name manf
Buddies
1 2
Buddies(name1, name2)
9
Combining Relations
• OK to combine into one relation:1. The relation for an entity-set E 2. The relations for many-one
relationships from E (“many”) to F
• Example: Drinkers(name, addr) and Favorite(drinker, beer) combine to make Drinker1(name, addr, favBeer).
10
Combining Relations (II)
• The combined relation schema consists of All attributes of E The key attributes of F Any attributes belonging to the
relationship R
• Can we combine one-one relationship?
• What about many-many?
11
Risk with Many-Many Relationships
• Combining Drinkers with Likes would be a mistake. It leads to redundancy, as:
name addr beerSally 123 Maple BudSally 123 Maple Miller
Redundancy
12
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 relationship is redundant and yields no relation.