The E-R Model <ul><li>Prof. Sin-Min Lee  </li></ul><ul><li>Department of Computer Science </li></ul>CS 157A Lecture 3
 
 
 
E-R Model <ul><li>The E-R model is not intended to be associated with any particular database model.  </li></ul><ul><li>E-...
 
History of E-R Model <ul><li>E-R Model was proposed by Dr. Peter Chen (currently professor at Louisiana State University) ...
The Entity-Relationship Model (History) <ul><li>Developed by Peter Chen in the 1970’s </li></ul><ul><li>Several variations...
 
The Entity-Relationship Approach <ul><li>Entity: an object that exists and is distinguishable from other objects.  i.e. pe...
More Terminology <ul><li>Object : things in the real world that can be observed and classified because they have related p...
 
 
Three Basic Graphical Symbols in an ER Diagram <ul><li>Rectangles are used to model conceptual data units or data objects....
 
 
BASIC CONCEPTS <ul><li>There are 3 basic notions in the E-R Model: </li></ul><ul><ul><ul><li>Entity Sets </li></ul></ul></...
AN ENTITY  <ul><li>An  entity  is a “thing” or “object” in the real world that is distinguishable from all other objects. ...
ENTITY SETS <ul><li>An  entity set  is a set of entities that share the same properties or attributes. Entity sets do not ...
ATTRIBUTE <ul><li>An entity is  represented by a set of  attributes .   Attributes   are descriptive properties possessed ...
ATTRIBUTE TYPES <ul><li>There are several different types of attributes. </li></ul><ul><ul><ul><li>Simple  and  Composite ...
ATTRIBUTE TYPES  <ul><li>Simple attributes   are not divided into subparts. </li></ul><ul><li>Composite attributes   can b...
ATTRIBUTE TYPES <ul><li>Example: address ( Composite attribute ) </li></ul><ul><li>  street  city state zip </li></ul><ul>...
ATTRIBUTE TYPES  <ul><li>Single-valued attributes   are attributes that only have a single value for a particular entity. ...
ATTRIBUTE TYPES <ul><li>Null attribute   is used when an entity does not have a value for an attribute. </li></ul><ul><li>...
RELATIONSHIP SETS <ul><li>A  relationship   is an association among several entities. </li></ul><ul><li>A  relationship se...
RECURSIVE RELATIONSHIP <ul><li>Recursive relationship - the same entity set participates in a relationship set more than o...
BINARY RELATIONSHIP SETS <ul><li>Binary relationship set  - relationship that involves two identity sets. </li></ul><ul><l...
TERNARY RELATIONSHIP SET  <ul><li>Ternary relationship set  - relationship that involves three identity sets </li></ul>DEG...
DEGREE OF A  RELATIONSHIP SET  <ul><li>Degree of a relationship set   is the number of entity sets that participate in a r...
CONSTRAINTS <ul><li>An E-R enterprise scheme may define certain constraints to which the contents of a database must confo...
CONSTRAINTS <ul><li>Mapping Cardinalities or Cardinality ratios </li></ul><ul><li>Express the number of entities to which ...
MAPPING CARDINALITIES <ul><li>One to one </li></ul><ul><li>An entity in A is associated with  at most   one entity in B, a...
MAPPING CARDINALITIES <ul><li>One to many </li></ul><ul><li>An entity in A is associated with any number (zero or more) of...
MAPPING CARDINALITIES <ul><li>Many to one </li></ul><ul><li>An entity in A is associated with  at most  one entity in B. A...
MAPPING CARDINALITIES <ul><li>Many to many </li></ul><ul><li>An entity in A is associated with any number (zero or more) o...
KEYS <ul><li>A  key   allows us to identify a set of attributes that  </li></ul><ul><li>suffice to distinguish entities fr...
KEY <ul><li>Superkey   is a set of one or more attributes that, taken collectively,  us to identify uniquely an entity in ...
RELATIONSHIP SETS <ul><li>Primary key of an entity set allows us to distinguish among entities of the set. Similar mechani...
RELATIONSHIP SETS <ul><li>For example, suppose that there is a relationship set  Depositor , with attribute access-date, b...
RELATIONSHIP SETS <ul><li>Customer ( ss#  , name) </li></ul><ul><li>Account ( account-num ) </li></ul><ul><li>Depositor ( ...
DESIGN ISSUE <ul><li>Use of Entity Sets versus Attributes </li></ul><ul><li>Consider the entity set  employee  with attrib...
USE OF ENTITY SETS VERSUS ATTRIBUTES <ul><li>Treating a telephone as an attribute </li></ul><ul><li>Treating a telephone a...
ENTITY-RELATIONSHIP DIAGRAM <ul><li>Ellipses , which represent attributes </li></ul><ul><li>Diamonds , which represent rel...
Example of the 3 elements in E/R Diagram
Classification of Constraints <ul><li>Keys </li></ul><ul><li>Single-value constraints </li></ul><ul><li>Multi-valued   con...
Key in the E/R Model <ul><li>Superkey  is a set of one or more attributes that, taken collectively, for us to identify uni...
Single/Multi-valued attributes <ul><li>Single-valued attributes  are attributes that only have a single value for a partic...
 
Mapping Cardinalities or Cardinality ratios  <ul><li>Express the number of items to which another item can be associated v...
Participation Constraints  <ul><li>The participation of an entity set E in a relationship set R is said to be  total , if ...
Weak Entity Sets <ul><li>There is an occasional condition in which an entity set’s key is composed of attributes some or a...
Discriminator <ul><li>The discriminator of a  weak entity set  is a set of attributes that allows this distinction to be m...
Requirements for Weak Entity Sets <ul><li>We cannot obtain key attributes for a weak entity set indiscriminately.  Rather,...
Discriminator (cont.) <ul><li>Note: although each payment entity is distinct, payments for different loans may share the s...
Identifying a Weak Entity Type <ul><li>A Weak entity type doesn’t have a primary key. </li></ul><ul><li>If X is a weak ent...
*  Doted-line = double-line *
Detailed Conceptual Design Employee Emp No unique identifier of an emp . Identifier Emp Name name of an employee Composite...
Detailed Conceptual Design Emp No Emp Name NID Salary Address Employee Gender DOB First Name Mid Initials Last Name
Employee works Department Project manage control works on supervise Dependent has Depd Name Gender DOB Relation Emp No Emp...
Conceptual Design with Weak Entities Employee works Department Project manage control works on supervise Dependent has
Upcoming SlideShare
Loading in …5
×

27 fcs157al3

2,837 views

Published on

Published in: Health & Medicine, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,837
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
146
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • 5 5
  • 3 2
  • 27 fcs157al3

    1. 1. The E-R Model <ul><li>Prof. Sin-Min Lee </li></ul><ul><li>Department of Computer Science </li></ul>CS 157A Lecture 3
    2. 5. E-R Model <ul><li>The E-R model is not intended to be associated with any particular database model. </li></ul><ul><li>E-R diagrams are intended to allow humans the ability to capture more of the application’s meaning. </li></ul>
    3. 7. History of E-R Model <ul><li>E-R Model was proposed by Dr. Peter Chen (currently professor at Louisiana State University) </li></ul><ul><li>Chen’s original paper on E-R Model is the 35 th most sited paper in computer science </li></ul><ul><li>Chen has written papers interconnecting E-R model and linguistics </li></ul>
    4. 8. The Entity-Relationship Model (History) <ul><li>Developed by Peter Chen in the 1970’s </li></ul><ul><li>Several variations have evolved </li></ul><ul><li>All are designed towards the concise capture of the application semantics in terms appropriate for subsequent mapping to a specific database model. </li></ul><ul><li>It is currently the most widely used . </li></ul>
    5. 10. The Entity-Relationship Approach <ul><li>Entity: an object that exists and is distinguishable from other objects. i.e. person, place, thing, event or concept about which information(attributes) is recorded. The basic unit of the E-R model. </li></ul><ul><li>The structure of an entity is called its schema. </li></ul>
    6. 11. More Terminology <ul><li>Object : things in the real world that can be observed and classified because they have related properties </li></ul><ul><li>Entity : the groupings we use when we categorize the objects. Sometimes called a class. </li></ul>
    7. 14. Three Basic Graphical Symbols in an ER Diagram <ul><li>Rectangles are used to model conceptual data units or data objects. </li></ul><ul><li>Circles are used to model attributes. Attributes are the characteristics, components or properties of entities. </li></ul><ul><li>Diamonds are used to model the structural associations that exist between entities. </li></ul>Course CID Enroll
    8. 17. BASIC CONCEPTS <ul><li>There are 3 basic notions in the E-R Model: </li></ul><ul><ul><ul><li>Entity Sets </li></ul></ul></ul><ul><ul><ul><li>Relationship Sets </li></ul></ul></ul><ul><ul><ul><li>Attributes </li></ul></ul></ul>
    9. 18. AN ENTITY <ul><li>An entity is a “thing” or “object” in the real world that is distinguishable from all other objects. It has an unique set of properties that may uniquely identify an entity. For example, a student entity has three attributes: name , student-id, and social-security numbers. </li></ul>STUDENT entity 123-12-2244 1222 John
    10. 19. ENTITY SETS <ul><li>An entity set is a set of entities that share the same properties or attributes. Entity sets do not need to be disjoint. For example, a customer can also be an employee. </li></ul>Customer (Entity Set) Employee (Entity Set) 723-12-2244 3222 Steve 223-22-2245 2223 Kathy 123-12-2244 1222 John Teller Steve Teller Kathy Manager John
    11. 20. ATTRIBUTE <ul><li>An entity is represented by a set of attributes . Attributes are descriptive properties possessed by each member of an entity set. </li></ul><ul><li>Example: </li></ul>STUDENT ss# student-id address name STUDENT entity Attributes
    12. 21. ATTRIBUTE TYPES <ul><li>There are several different types of attributes. </li></ul><ul><ul><ul><li>Simple and Composite </li></ul></ul></ul><ul><ul><ul><li>Single-valued and Multivalued </li></ul></ul></ul><ul><ul><ul><li>Derived </li></ul></ul></ul><ul><ul><ul><li>Null </li></ul></ul></ul>
    13. 22. ATTRIBUTE TYPES <ul><li>Simple attributes are not divided into subparts. </li></ul><ul><li>Composite attributes can be divided into subparts. </li></ul><ul><li>Using composite attributes in a design schema is a </li></ul><ul><li>good choice if a user will wish to refer to an entire </li></ul><ul><li>attribute on some occasions. </li></ul>
    14. 23. ATTRIBUTE TYPES <ul><li>Example: address ( Composite attribute ) </li></ul><ul><li> street city state zip </li></ul><ul><li>street-number street-name apartment-number </li></ul>Composite attribute
    15. 24. ATTRIBUTE TYPES <ul><li>Single-valued attributes are attributes that only have a single value for a particular entity. </li></ul><ul><li>Multi-valued attributes refers to entities that are not singled-value and Null valued. For example, consider an employee entity set with the attribute phone-number. An employee may have zero, one, or several phone numbers, different employee may have different numbers of phones. </li></ul>
    16. 25. ATTRIBUTE TYPES <ul><li>Null attribute is used when an entity does not have a value for an attribute. </li></ul><ul><li>Derived attributes refer to an attribute that can be derived </li></ul><ul><li>from other related attributes or entities. For instance, suppose that Age and Date-of-birth are attributes of the CUSTOMER entity set. We can calculate Age from Date-of-birth . In this case, Age is a derived attribute . </li></ul>
    17. 26. RELATIONSHIP SETS <ul><li>A relationship is an association among several entities. </li></ul><ul><li>A relationship set is a set of relationships of the same type. Consider the two entity sets customer and loan . We define the relationship set borrower to denote the association between customers and bank loans that the customers have. </li></ul>customer loan Rye North Smith 019-28-3746 Pittsfield Spring Adam 321-12-3123 Rye North Curry 321-12-3123 Woodside Dupont Jackson 555-55-5555 Harrison Main Jones 321-12-3123 1300 L-16 500 L-19 1500 L-14 2000 L-23 1000 L-17
    18. 27. RECURSIVE RELATIONSHIP <ul><li>Recursive relationship - the same entity set participates in a relationship set more than once, in different roles. The function that an entity plays in a relationship is called that entity’s role . For example, consider an entity set employee that records information about all employees of the bank. We may have a relationship set works-for that is modeled by ordered pairs of employee entities. The first employee of a pair takes the role of worker , whereas the second takes the role of manager . </li></ul>employee employee-name telephone-number employee-id works-for manager worker Recursive Relationship
    19. 28. BINARY RELATIONSHIP SETS <ul><li>Binary relationship set - relationship that involves two identity sets. </li></ul><ul><li>Most of the relationship sets in a database system are binary. Occasionally, however, relationship set involve more than two entity. </li></ul>OWNER Owns PROPERTY-FOR-RENT Binary relationship called Owns
    20. 29. TERNARY RELATIONSHIP SET <ul><li>Ternary relationship set - relationship that involves three identity sets </li></ul>DEGREE DATE PERSON earned PERSON earned DEGREE on DATE Ternary Relationship Set
    21. 30. DEGREE OF A RELATIONSHIP SET <ul><li>Degree of a relationship set is the number of entity sets that participate in a relationship set. For example, a binary relationship set is of degree 2; a ternary relationship set is of degree 3. </li></ul>
    22. 31. CONSTRAINTS <ul><li>An E-R enterprise scheme may define certain constraints to which the contents of a database must conform. The two of most important types of constraints are Mapping Cardinalities and Participation Constraints . </li></ul><ul><li>Participation Constraints </li></ul><ul><li>The participation of an entity set E in a relationship set R is said to be total , if every entity in E participates in at least one relationship in R. If only some entities in E participate in relationship R, the participation of entity set E in relationship R is said to be partial . </li></ul>
    23. 32. CONSTRAINTS <ul><li>Mapping Cardinalities or Cardinality ratios </li></ul><ul><li>Express the number of entities to which another entity can be associated via a relationship set </li></ul><ul><li>Are most useful in describing binary relationship sets. For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following: </li></ul><ul><li>One to one </li></ul><ul><li>One to many </li></ul><ul><li>Many to one </li></ul><ul><li>Many to many </li></ul>
    24. 33. MAPPING CARDINALITIES <ul><li>One to one </li></ul><ul><li>An entity in A is associated with at most one entity in B, and an entity in B is associated with at most one entity in A. </li></ul>A3 B2 B1 B3 A1 A2 A B
    25. 34. MAPPING CARDINALITIES <ul><li>One to many </li></ul><ul><li>An entity in A is associated with any number (zero or more) of entities in B. An entity in B, however, can be associated with at most one entity in A. </li></ul>A3 B3 B2 B4 A1 A2 A B B1
    26. 35. MAPPING CARDINALITIES <ul><li>Many to one </li></ul><ul><li>An entity in A is associated with at most one entity in B. An entity in B, however, can be associated with any number (zero or more) of entities in A. </li></ul>A3 B2 B1 B3 A1 A2 A B A1
    27. 36. MAPPING CARDINALITIES <ul><li>Many to many </li></ul><ul><li>An entity in A is associated with any number (zero or more) of entities in B, and an entity in B is associated with any number (zero or more) of entities in A. </li></ul>A3 B2 B1 B3 A1 A2 A B A1
    28. 37. KEYS <ul><li>A key allows us to identify a set of attributes that </li></ul><ul><li>suffice to distinguish entities from each other. Keys </li></ul><ul><li>also help uniquely identify relationships, and thus </li></ul><ul><li>distinguish relationships from each other. There are </li></ul><ul><li>three types of keys: </li></ul><ul><ul><ul><li>Super key </li></ul></ul></ul><ul><ul><ul><li>Candidate key </li></ul></ul></ul><ul><ul><ul><li>Primary key </li></ul></ul></ul>
    29. 38. KEY <ul><li>Superkey is a set of one or more attributes that, taken collectively, us to identify uniquely an entity in the entity set. For example, customer-id is a superkey . </li></ul><ul><li>Candidate key is a minimal superkey. For example, customer-name and customer-street is sufficient to distinguish among members of the customer entity set. Then {customer-name, customer-street} is a candidate key . </li></ul><ul><li>Primary key denotes a candidate key that is chosen by the database designer as the principal means of identifying entities within an entity set. the primary key should be chosen such that its attributes are never, or very rarely, changed. For example, Social-security numbers are guaranteed to never changed. </li></ul>
    30. 39. RELATIONSHIP SETS <ul><li>Primary key of an entity set allows us to distinguish among entities of the set. Similar mechanism is needed in order to distinguish among the various relationships of a relationship set. </li></ul><ul><li>The structure of the primary key for the relationship set depends on the mapping cardinality of the relationship set. </li></ul>
    31. 40. RELATIONSHIP SETS <ul><li>For example, suppose that there is a relationship set Depositor , with attribute access-date, between Customer relation and Account relation. Suppose that the relationship set is many to many . Then the primary key of Depositor consists of the union of the primary keys of Customer and Account . If a customer can have only one account- that is, if the Depositor relation is many to one from Customer to Account - then the primary key of the Depositor relationship is simply the primary key of customer. </li></ul>
    32. 41. RELATIONSHIP SETS <ul><li>Customer ( ss# , name) </li></ul><ul><li>Account ( account-num ) </li></ul><ul><li>Depositor ( ss# , account-num , access-date) </li></ul>Customer Account 24 May 2002 3 June 2002 20 June 2002 21 June 2002 10 May 2002 Depositor 723-12-2244 Steve 223-22-2245 Kathy 123-12-2244 John A-102 A-215 A-101
    33. 42. DESIGN ISSUE <ul><li>Use of Entity Sets versus Attributes </li></ul><ul><li>Consider the entity set employee with attributes employee-name and telephone-number . </li></ul><ul><li>Treating a telephone as an attribute telephone-number implies that employees have precisely one telephone number each. </li></ul><ul><li>Treating a telephone as an entity telephone permits employees to have several telephone number ( including zero) associated with them. However, we could instead easily define telephone-number as a multivalued attribute to allow multiple telephones per employee. </li></ul>
    34. 43. USE OF ENTITY SETS VERSUS ATTRIBUTES <ul><li>Treating a telephone as an attribute </li></ul><ul><li>Treating a telephone as an entity </li></ul>EMPLOYEE (employee-name, telephone-number) TELEPHONE(telephone-number, type) EMPLOYEE (employee-name) cell-phone 408-888-3565 cell-phone 714-555-6366 cell-phone 408-222-3455 video-phone 408-345-5366 714-555-6366 Steve 408-222-3455 Kathy 408-345-5366 John John Alex Steve Kathy
    35. 44. ENTITY-RELATIONSHIP DIAGRAM <ul><li>Ellipses , which represent attributes </li></ul><ul><li>Diamonds , which represent relationship sets </li></ul><ul><li>Line , which link attributes to entity sets and entity sets to relationships sets </li></ul><ul><li>Double ellipses , which represent multivalued attributes </li></ul><ul><li>Double lines , which indicate total participation of an entity </li></ul><ul><li>in a relationship set </li></ul><ul><li>Double rectangles , which represent weak entity sets </li></ul>
    36. 45. Example of the 3 elements in E/R Diagram
    37. 46. Classification of Constraints <ul><li>Keys </li></ul><ul><li>Single-value constraints </li></ul><ul><li>Multi-valued constraints </li></ul><ul><li>Mapping Cardinalities and Participation Constraints </li></ul>
    38. 47. Key in the E/R Model <ul><li>Superkey is a set of one or more attributes that, taken collectively, for us to identify uniquely an item in the entity set. For example, customer-id is a superkey. </li></ul><ul><li>Candidate key is a minimal superkey. For example, customer-name and customer-street is sufficient to distinguish among members of the customer entity set. Then {customer-name, customer-street } is a candidate key. </li></ul><ul><li>Primary key denotes a candidate key that is chosen by the database designer as the principal means of identifying items within an entity set. the primary key should be chosen such that its attributes are never, or very rarely, changed. For example, Social-security numbers are guaranteed to never changed. </li></ul>
    39. 48. Single/Multi-valued attributes <ul><li>Single-valued attributes are attributes that only have a single value for a particular entity. </li></ul><ul><li>Multi-valued attributes refers to items that are not singled-value and Null valued. For example, consider an employee entity set with the attribute phone-number. An employee may have zero, one, or several phone numbers; different employee may have different numbers of phones. </li></ul>
    40. 50. Mapping Cardinalities or Cardinality ratios <ul><li>Express the number of items to which another item can be associated via a relationship set </li></ul><ul><li>Are most useful in describing binary relationship sets. For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following: </li></ul><ul><ul><li>One to One </li></ul></ul><ul><ul><li>One to Many </li></ul></ul><ul><ul><li>Many to One </li></ul></ul><ul><ul><li>Many to Many </li></ul></ul>
    41. 51. Participation Constraints <ul><li>The participation of an entity set E in a relationship set R is said to be total , if every item in E participates in at least one relationship in R. If only some items in E participate in relationship R, the participation of entity set E in relationship R is said to be partial . </li></ul>
    42. 52. Weak Entity Sets <ul><li>There is an occasional condition in which an entity set’s key is composed of attributes some or all of which belong to another entity set. Such an entity set is called a weak entity set . </li></ul>
    43. 53. Discriminator <ul><li>The discriminator of a weak entity set is a set of attributes that allows this distinction to be made. For example, the discriminator of a weak entity set payment is the attribute payment-number, since, for each loan a payment number uniquely identifies one single payment for that loan. The discriminator of a weak entity set is also called the partial key of the entity set. </li></ul>
    44. 54. Requirements for Weak Entity Sets <ul><li>We cannot obtain key attributes for a weak entity set indiscriminately. Rather, if E is a weak entity set then its key consists of: </li></ul><ul><ul><li>Zero or more of its own attributes, and </li></ul></ul><ul><ul><li>Key attributes from entity sets that are reached by certain many-one relationship from E to other entity sets. These many-one relationship are called supporting relationships for E. </li></ul></ul>
    45. 55. Discriminator (cont.) <ul><li>Note: although each payment entity is distinct, payments for different loans may share the same payment-number. Thus, payment entity set does not have a primary key; it is a weak entity set. </li></ul><ul><li>The primary key of a weak entity set is formed by the primary key of the identifying entity set, plus the weak entity set’s discriminator. </li></ul>
    46. 56. Identifying a Weak Entity Type <ul><li>A Weak entity type doesn’t have a primary key. </li></ul><ul><li>If X is a weak entity type and Y is the entity type on which X is dependent. </li></ul><ul><li>We form a primary key for X by combining the primary key of Y which one or more attributes, called discriminator or partial key , from X. </li></ul><ul><li>In an E/R Diagram, a partial key is usually dash-underlined. </li></ul><ul><li>e.g., primary key for DEPENDENT: {Employee No., DName}. </li></ul>
    47. 57. * Doted-line = double-line *
    48. 58. Detailed Conceptual Design Employee Emp No unique identifier of an emp . Identifier Emp Name name of an employee Composite First Name first name of an employee Mid Initials middle initials of an employee Last Name last name of an employee NID national id of an employee Unique Address address of an employee Salary salary of an employee Gender sex of an employee DOB birth date of an employee
    49. 59. Detailed Conceptual Design Emp No Emp Name NID Salary Address Employee Gender DOB First Name Mid Initials Last Name
    50. 60. Employee works Department Project manage control works on supervise Dependent has Depd Name Gender DOB Relation Emp No Emp Name NID Salary Address Gender DOB First Name Mid Initials Last Name Proj No Proj Name Location Dept No Dept Name Location Employees Phone Hours Start d
    51. 61. Conceptual Design with Weak Entities Employee works Department Project manage control works on supervise Dependent has

    ×