Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.

Similar presentations


Presentation on theme: "The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006."— Presentation transcript:

1 The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006

2 Lecture 2© CIS 4301 - Spring 20062 Database Modeling Analysis of what information the database must hold Relationships among components of that information Database schema is specified in one of several languages or notations suitable for expressing designs Next, design is committed to a form which can be input to a DBMS  DB takes on physical existence Design notation in this course is Entity-Relationship (E/R) model Ideas ODL, UML, etc. E/R Object-Oriented DBMS Relational DBMS Relations

3 Lecture 2© CIS 4301 - Spring 20063 Entity-Relationship Model Entity: Real-world object, concept, or event Entity type/set: Collection of entities of the same type; sets don’t have to be distinct Attribute: Values describing some property of an entity simple vs. composite single-valued vs. multi-valued stored vs. derived Relationship: Association between two or more entity sets Relationship type/set: Collection of relationships

4 Lecture 2© CIS 4301 - Spring 20064 Examples - “Movie Database” Entity: Movie, Star Attributes: Name : “Harrison Ford” (simple, single-valued, stored) Address : “123 Main Str., LA, CA” (complex) Birthdate : “1-1-50” (simple) Age : 50 (could be derived from Birthdate and current date) Entity Types: Stars (Name,Address,Birthdate,Age) Movies(Title,Year,Length,FilmType)

5 Lecture 2© CIS 4301 - Spring 20065 E/R Diagrams - Notation Entity Set Relationship Set Attribute Multivalued Derived... Composite Attribute Role Name

6 Lecture 2© CIS 4301 - Spring 20066 Sample Movie Database Movies Studios Stars Owns Stars-in titleyear length filmType nameaddress name streetcityzip

7 Lecture 2© CIS 4301 - Spring 20067 Relationships Define associations among entities Grouped together into relationships sets (types) Example: Relationship type: Stars-in between Movies and Stars Can be visualized as a table MoviesStars A. SchwarzeneggerTotal Recall Sharon StoneTotal Recall Sharon StoneBasic Instinct Relationships Relationship Type Stars-in

8 Lecture 2© CIS 4301 - Spring 20068 Relationships Cont’d Degree of a relationship type is the number of participating entity types binary, ternary, n-ary Another example: Entities: Stars, Movies, Studios Ternary Relationship Set: Contracts Each entity type that participates in a relationship type plays a role in the relationship Marked by (optional) name Entity type may play multiple roles in a relationship type (see example later)

9 Lecture 2© CIS 4301 - Spring 20069 Relationships Cont’d Relationships can have attributes Example: Relationship type Contracts between Stars and Studios for Movies Might want to record salary associated with each contract Not necessary to place attributes on relationships; instead, can invent new entity type whose entities have the attributes ascribed to the relationship

10 Lecture 2© CIS 4301 - Spring 200610 Multiplicity of Binary Relationships Limit the possible combinations of entities that participate in the relationship type Derived from real-world scenario which is being modeled a.k.a cardinality ratio Specifies the number of relationships an entity can participate in 1:1, 1:N, N:1, N:M Example: Stars-in between Stars and Movies is N:M from Stars to Movies

11 Lecture 2© CIS 4301 - Spring 200611 Multiplicity In a many-many relationship, an entity of either set can be connected to many entities of the other set In a many-one relationship, each entity of the first set is connected to at most one entity of the second set An entity of the second set can be connected to zero, one, or many entities of the first set In a one-one relationship, each entity of either set is connected to at most one entity of the other set

12 Lecture 2© CIS 4301 - Spring 200612 In Pictures… many-many many-oneone-one

13 Lecture 2© CIS 4301 - Spring 200613 Multiplicity in the E/R Model Use arrow pointing to “one” side of relationship many-many many-one one-one N N N1 11 letters optional

14 Lecture 2© CIS 4301 - Spring 200614 Sample Movie Database Movies Studios Stars Owns Stars-in titleyear length filmType nameaddress name M N 1 N streetcityzip

15 Lecture 2© CIS 4301 - Spring 200615 Multi-way Relationships Movies Studios Stars Contracts 1 N N MoviesStars SchwarzeneggerTotal Recall Sharon StoneTotal Recall Sharon StoneBasic Instinct Studios MGM Universal H. FordStar WarsFox “1” means that if we select one entity from each of the other entity sets in the relationship, those entities are related to a unique entity in Studios “Contracts” Relationship Ternary

16 Lecture 2© CIS 4301 - Spring 200616 Multi-way Relationships Movies Studios Stars Contracts 1 N N “1” means that if we select one entity from each of the other entity sets in the relationship, those entities are related to a unique entity in Studios 1 Producing Studio Studio of Star 4-way

17 Lecture 3© CIS 4301 - Fall 200317 Subclass/Superclass Often, class contains certain objects that have special properties not associated with all members Useful to organize class into subclasses Each having its own special attributes and/or relationships In addition to those of the superclass Example Superclass: Movies Subclasses: Cartoons, Mystery, Science- Fiction

18 Lecture 3© CIS 4301 - Fall 200318 Subclass in E/R Diagrams Assume subclasses form a tree (i.e., no multiple inheritance) ISA triangles indicate subclass relationship Point to the superclass

19 Lecture 3© CIS 4301 - Fall 200319 Example Movies titleyearlengthfilmType Cartoons Murder Mysteries weapon Voices N M Indicates direction of superclass/subclass relationship ISA

20 Lecture 3© CIS 4301 - Fall 200320 Inheritance Entity in subclass represents same real-world entity as in the superclass Should possess values for its specific attributes As well as values for the attributes it inherits from its superclass Entity inherits all attributes defined on superclass and the relationships in which superclass participates

21 Lecture 3© CIS 4301 - Fall 200321 E/R vs. Object-Oriented Subclasses In object-oriented world, objects are in one class only Subclasses inherit properties from superclasses In contrast, E/R entities have components in all subclasses to which they belong

22 Lecture 3© CIS 4301 - Fall 200322 Example Movies titleyearlengthfilmType Cartoons Murder Mysteries weapon Voices How do we represent a cartoon-murder- mystery? N M contents may overlap ISA The Pink Panther

23 Lecture 3© CIS 4301 - Fall 200323 Another Example Accounts account-number balance Savings Accounts Checking Accounts overdraft-amountinterest-rate contents are disjoint ISA disjoint

24 Lecture 3© CIS 4301 - Fall 200324 Design Principles Faithfulness Avoid redundancy Relationship Owns between Movies and Studios; adding attribute studioName to Movies would be redundant Simplicity counts Movies Studios Owns Name Studio Name redundant

25 Lecture 3© CIS 4301 - Fall 200325 Example Movies Studios Stars Owns Stars-in titleyear length filmType nameaddress name M N 1 N streetcityzip Works for ??

26 Lecture 3© CIS 4301 - Fall 200326 Design Principles Picking the right kind of element Many of the choices are between using attributes and using entities E.g., Should we have eliminated Studios and made name and address attributes of Movies instead? If something has more info than just a name, it probably needs to be an entity type

27 Lecture 3© CIS 4301 - Fall 200327 Example Movies Stars Stars-in titleyear length filmType nameaddress name M N streetcityzip ??

28 Lecture 3© CIS 4301 - Fall 200328 Example AcctSetsCustomers Accounts Addresses number balance Member of address Lives at Has name owner- address


Download ppt "The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006."

Similar presentations


Ads by Google