Anda di halaman 1dari 33

E-R

E-R Model
Model
Entity-Relationship Model
• Entity Sets
• Relationship Sets
• Design Issues
• Mapping Constraints
• Keys
• E-R Diagram
• Extended E-R Features
Entity Sets
• A database can be modeled as:
– a collection of entities,
– relationship among entities.
• An entity is an object that exists and is distinguishable from
other objects.
– Example: specific person, company, event, plant
• Entities have attributes
– Example: people have names and addresses
• An entity set is a set of entities of the same type that share the
same properties.
– Example: set of all persons, companies, trees, holidays
Entity Sets customer and loan
customer-id customer- customer- customer- loan- amount
name street city number
Attributes
• 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
• Attribute types:
– Simple and composite attributes.
– Single-valued and multi-valued attributes
• E.g. multivalued attribute: phone-numbers
– Derived attributes
• Can be computed from other attributes
• E.g. age, given date of birth
Composite Attributes
Relationship Sets
• A relationship is an association among several
entities
Example:
Hayesdepositor A-102
customer entityrelationship setaccount entity
• A relationship set 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


– Example:
(Hayes, A-102)  depositor
Relationship Set
borrower
Constraints
• Mapping Cardinalities
• Keys
• Participation Constraints
Mapping Cardinalities
• Express the number of entities to which another
entity can be associated via a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mapping
cardinality must be one of the following types:
– One to one
– One to many
– Many to one
– Many to many
Mapping Cardinalities
Mapping Cardinalities

One to one One to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
Mapping Cardinalities
Mapping Cardinalities

Many to one Many to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
Keys
Super key
• set of one or more attributes that, taken collectively,
allow us to identify uniquely an entity in the entity set
Eg: {customer_id}
{customer_id,customer_name}
Candidate Key
• no proper subset of superkey
Primary Key
• attributes are never, or very rarely,Changed
Eg: {PAN_NO}
Participation Constraints
• Total
Every entity in E participates in at
least one relationship in R
• Partial
Some entity in E participates in at
least one relationship in R
E-R Diagrams
• Rectangles, which represent entity sets
• Ellipses, which represent attributes
• Diamonds, which represent relationship sets
• Lines, which link attributes to entity sets and
entity sets to relationship sets
• Double ellipses, which represent multi valued
attributes
• Dashed ellipses, which denote derived attributes
• Double lines, which indicate total participation of
an entity in a relationship set
• Double rectangles, which represent weak entity
sets
Customer Loan
- Customer_id - loan_number
- Customer_name - amount
- Customer_street
– Customer_city
E-R diagram corresponding to
customers and loans.
Relationships. (a) one to many. (b) many to one. (c) one-to-one.
E-R diagram with an attribute
attached to a relationship set.
E-R diagram with composite, multi
valued, and derived attributes.
Customer entity set
 Customer_id
 Name(first_name,middle_name
last_name)
 Address(street,city,state,
zip_code)
 Age
 Date_of_birth
 Phone_number
E-R diagram with role
indicators.
E-R diagram with a ternary
relationship.
Total participation of an entity
set in a relationship set
Weak Entity Sets
• An entity set may not have sufficient
attributes to form a primary key.
Such an entity set is termed a weak
entity set.
E-R diagram with a
weak entity set.
Extended E-R Features
• Specialization
• Generalization
• Attribute Inheritance
• Constraints on Generalizations
• Aggregation
Specialization
• The process of designating sub groupings
within an entity set is called
specialization.
Generalization
• generalization, which is a
containment relationship that exists
between a higher-level entity set and
one or more lower-level entity sets.
Specialization
and
generalization Higher level entity set
(or) super class

lower level entity set (or)


sub class
Attribute Inheritance
• A crucial property of the higher- and lower-
level entities created by specialization and
generalization is attribute inheritance. The
attributes of the higher-level entity sets are
said to be inherited by the lower-level entity
sets.
Aggregation
Aggregation is an abstraction through which relationships are treated as
higher level entities.
E-R diagram for library

Anda mungkin juga menyukai