Chapter 2: Entity-Relationship Model
Chapter 2: Entity-Relationship Model
Chapter 2: Entity-Relationship Model
Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an E-R Database Schema Reduction of an E-R Schema to Tables
Entity set
Eg:CUSTOMER LOAN
CUSTOMER
LOAN
An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Example: customer = (customer-id, customer-name, customer-street, customer-city) loan = (loan-number, amount) Domain the set of permitted values for each attribute In E-R diagram an Attribute is represented by Ellipse
Customer -Id Customer -Name Customer -Street
Attributes
LoanNumber
Amount
LOAN CUSTOMER
Customer -City
Attribute types
Simple and composite attributes Simple attributes are atomic, further decomposition is not possible. eg:- Age Composite attributes can be further decomposed into component attributes. Composite attributes help us to group together related attributes , making the modeling cleaner.
Single-valued and multi-valued attributes The attributes that have at most one value for a specific entity then it is called single valued attributes. Eg:- Age There may be instances where an attribute has set of values for a specific entity. Such attribute that can have more than one value for a specific entity is called Multi valued Attribute. Eg:- Phone- numbers Stored and derived Attributes The value of derived attribute can be derived from an existing attribute (Stored Attribute) Eg:- The age (derived Attribute) can be derived from Date of birth (Stored Attribute)
Ellipses represent attributes Double ellipses represent multi valued attributes. (phone-number) Dashed ellipses denote derived attributes (Age) Composite attributes are represented by a hierarchy of attributes
Relationship Sets
A relationship is an association among several entities Suppose a customer Hayes have a loan of L -15. Hayes is associated with L-15 ( Borrower ) Example: Hayes Borrower L-15 A relationship set is a set of relationship of the same type. Formally it is a mathematical relation among n 2 entities, each taken from entity sets {(e1, e2, en) | e1 E1, e2 E2, , en En} where (e1, e2, , en) is a relationship, E1,E2 are called participation Entities. Example: (Hayes, L-15) Borrower
Relationship
Relationships between more than two entity sets are rare. Most relationships are binary. (More on this later.)
Roles
The function that an entity plays in a relationship is called that entitys role. The participating entities in a relationship set are generally distinct , roles are implicit and are not usually specified. Entity sets of a relationship need not be distinct. i.e. same entity set participates more than once in a relationship (recursive relation ship). In that case it is necessary to specify how an entity participate (role) in a relationship The labels manager and worker are called roles; they specify how employee entities interact via the works-for relationship set. Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles. Role labels are optional, and are used to clarify semantics of the relationship
For a binary relationship set R between entity set A and B , The mapping cardinality must be one of the following One to One :- 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 One to Many :- An entity in A is associated with any number of entities in B and an entity in B is Associated with at most one entity in A
One to One
One to Many
Many to One:- An entity in A is associated with at most one entity in B and an entity in B is Associated with any number of entities in A Many to Many :- An entity in A is associated with any number of entities in B and an entity in B is Associated with any number of entities in A
Many to One
Many to Many
In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower
In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower
Many-To-Many Relationship
A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower
Existence Dependencies
The existence of an entity X depends on the existence of another entity Y , then X is said to be Existence depends on Y Y Dominant Entity X subordinate Entity. If Y is deleted , that should automatically delete X also E.g.:- The existence of payment details depends on Loan The participation of an entity in a relationship is closely related to Existence dependency.
Keys
A super key of an entity set is a set of one or more attributes whose values uniquely determine each entity. E.g. {Social-Security} If K is a super key then the superset of K is also super key The concepts of Super key is not sufficient because it may contain extraneous attributes A candidate key of an entity set is a minimal super key, a super key in which no proper subset is a super key. Customer-id is candidate key of customer account-number is candidate key of account Although several candidate keys may exist, one of the candidate keys is selected to be the primary key. The term Primary key is used to denote a candidate key that is chosen by the designer as the principle means of identifying entities within an entity set
E-R Diagrams
Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes.
Specialization
Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set. These subgroupings become lower-level entity sets that have attributes or participate in relationships that do not apply to the higher-level entity set. Depicted by a triangle component labeled ISA (E.g. customer is a person). Attribute inheritance a lower-level entity set inherits all the attributes and relationship participation of the higher-level entity set to which it is linked.
Specialization Example
Generalization
A bottom-up design process combine a number of entity sets that share the same features into a higher-level entity set. Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way. The terms specialization and generalization are used interchangeably.
user-defined
Constraint on whether or not entities may belong to more than one lower-level entity set within a single generalization.
Disjoint
an entity can belong to only one lower-level entity set Noted in E-R diagram by writing disjoint next to the ISA triangle
Overlapping
an entity can belong to more than one lower-level entity set
Aggregation
Consider the ternary relationship works-on, which we saw earlier Suppose we want to record managers for tasks performed by an employee at a branch
Aggregation (Cont.)
Relationship sets works-on and manages represent overlapping information
Every manages relationship corresponds to a works-on relationship However, some works-on relationships may not correspond to any manages relationships
So we cant discard the works-on relationship
( ii) Composite attributes are flattened out by creating a separate attribute for each component attribute
E.g. given entity set customer with composite attribute name with
component attributes first-name and last-name the table corresponding to the entity set has two attributes :first-name and last-name
(IV) A weak entity set becomes a table that includes a column for the primary key of the identifying strong entity set
Eg:- the weak entity Set Payment ( Payment-number ,payment-date, payment-amount) becomes
PAYMENT
Loan-Number Payment-number Payment-date Payment-amount
Where Loan- number is the primary key of the identifying relationship ( LOAN ) of Payment
Representing Relationship Sets as Tables A many-to-many relationship set is represented as a table with columns for the primary keys of the two participating entity sets, and any descriptive attributes of the relationship set. e.g.: table for relationship set borrower
BORROWER Customer-id Loan-Number
Many-to-one and one-to-many relationship sets that are total on the many-side can be represented by adding an extra attribute to the many side, containing the primary key of the one side E.g.: Instead of creating a table for relationship Loan-branch, add an attribute branch to the entity set Loan. Thus the LOAN table becomes Loan( Loan-number, amount, Branch)