Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.

Similar presentations


Presentation on theme: "The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file."— Presentation transcript:

1 The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file organization and index structures.

2 Terminology Title Year Length FilmType Star Wars 1997 124 color Mighty Ducks 1991 104 color Wayne’s World 1992 95 color...... tuples Attribute names components of tuples

3 More Terminology Every attribute has an atomic type. Relation Schema: relation name + attribute names + attribute types Relation instance: a set of tuples. Only one copy of any tuple! Database Schema: a set of relation schemas. Database instance: a relation instance for every relation in the schema.

4 From E/R Diagrams to Relations Entity sets become relations with the same set of attributes. Relationships become relations whose attributes are only: –The keys of the connected entity sets. –Attributes of the relationship itself.

5 Entity Sets to Relations titleyearlengthfilmtype Star Wars1977124Color Might Ducks1991104Color Wayne’s World199295Color Movies length filmType title year Relation schema: Movies(title, year, length, filmtype ) A relation instance:

6 E/R Relationships to Relations Relationships in the E/R model are also represented by relations. The relation for a given relationship R has the following attributes: –For each entity set involved in relationship, we take its key attribute(s) as part of the schema of the relation for R. –If the relationship has attributes, these are also attributes of relation R. When one entity set is involved several times in a relationship - or - the same attribute name appears in the keys of different ES participating in the relationship R, - or - even when we like to avoid confusion and to be clearer in meaning we should rename the attributes.

7 1.The relationship Owns between entity sets Movies and Studios is represented by a relation with schema: Owns(title,year,studioName). A sample instance is: titleyearstudioName Star Wars1977Fox Mighty Ducks1991Disney Example (with Renaming)

8 2.The relationship Stars-In between entity sets Movies and Stars is represented by a relation with schema: Stars-In(title, year, starName) 1.A sample instance is: title yearstarName Star Wars 1977Carrie Fisher Star Wars 1977Mark Hamill Star Wars 1977Harrison Ford Mighty Ducks 1991Emilio Estevez Wayne’s World 1992 Dana Carvey Wayne’s World 1992 Mike Meyers Example (with Renaming)

9 Likes(drinker, beer) Favorite(drinker, beer) Married(husband, wife) Buddies(name1, name2) LikesDrinkersBeers Favorite Married husband wife name addr name manf Buddies 1 2

10 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, favBeer).

11 Risk with Many-Many Relationships Combining Drinkers with Likes would be a mistake. Why? It leads to redundancy, as: name addr beer Sally 123 Maple Bud Sally 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 (double-diamond) relationship is redundant and yields no relation.

13 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


Download ppt "The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file."

Similar presentations


Ads by Google