Entity Relationship Diagram - New
Entity Relationship Diagram - New
E-R Diagrams are in the base of popularity and wide-spread use of the E-R model.
E-R diagrams are simple and clear. They do not include any implementation detail.
1. Entity Set
2. Attributes
3. Relationship sets
Entity Set
“ An Entity is a ‘thing’ or object’ existing in the real world that is distinguishable from all
other object.”
For Example, any Customer of a bank is an entity. A customer , say ‘Riya’, exists in a real
world, as she is living thing. She can be distinguishable from other customer based on her
cust_id, name address and other data. Also, she is different from an employee , an account,
a loan, a transaction or a branch.
Entity set:
Disjoint ness:
This means that, a single entity can be a member or extension of more than one entity set.
For example, a single person can be customer as well as an employee of a bank. And if so,
then he/she is an extension of both the entity sets- customer as well as employee.
Attributes
For Example, an entity set Customer has attributes like customer_id, name, address and
contact number denoted by c_id, cname, address, con_no respectively.
Types of Attributes:
Simple attribute cannot be divided into sub-parts. Simple attributes are also referred
as atomic attribute.
For example, cid,ano,balance,bname are simple attribute, as they cannot be divided
into sub-parts.
Single v/s Multi-valued Attribute:
Single valued attributes have single data value for a particular entity.
For example, cid and ano are single valued attributes. For any customer, there will be
only one customer id. Similarly, for any account, there will be only one account
number.
Multi-valued attributes have multiple data values for a particular entity.
For example, contact no is a multi-valued attributes, since any particular customer
can have zero, one or more contact numbers.
The value for derived attribute can be derived from the values of other related
attribute.
Consider two attribute age and birth_date for customer entity set. Here, age can be
calculated by using birth date and current date. So, age is considered as a derived
attribute, while birth_date is considered as a stored attribute or base attribute.
The value of a derived attribute is not stored in a database. But, it is computed from
stored attribute whenever required.
Relationship
In banking application, each and every account is associated with some particular
customer. This kind of association is known as relationship.
For example, there is relationship between a customer, say ‘janaki’ and some account ,
say account with account number ‘A01’. This relationship indicates that ‘A01’ account is
owned by a customer ‘janaki’ .
Relationship Set :
For example, two other entities sets loan and branch. A relationship set Loan_branch
denotes the association between a bank loan and the branch. Similarly, Account_branch
relationship can associate each account with a particular branch to which it belongs.
Cardinality Constraints
Cardinality constraints express the number of entities to which another entity can be
associated via a relationship set.
Based on mapping cardinalities, a binary relationship set can be divided into four categories:
1. One-to-One
2. One-to-Many
3. Many-to-One
4. Many-to-Many
1. One-to-One:
2. One-to-Many
For Example, multiple accounts are allowed, but no join accounts are allowed. So,
one customer can have any number of accounts, but one account will have only one
customer.
3. Many-to-One
For example, No multiple accounts are allowed, but join accounts are allowed. So
One customer can have only one account , but one account can be associated with any
number of accounts.
4. Many-to-Many
An entity in E1 is associated with zero or more entities of E2. Ans, an entity in E2 is
associated with zero or more entities of E1.
An example, Multiple accounts, as well as, joins accounts- both are allowed.
In this situation, one customer can have any number of accounts, and one account
can have any number of customers.
Key Constraints
Each and every entity in any entity set is different from other one.
From database perspective, this difference is represented by values of attributes for each
entity. No any two entities set will have exactly the same values for all attributes.
There must be some way to uniquely identify an entity within an entity set.
1. Super Key
2. Candidate Key
3. Primary Key
Super Key :
o A super key is a set of one or more attributes that allows identifying each
entity uniquely in the entity set.
o For example, the cid attribute of the entity set customer can distinguish one
customer from another. So, cid is a super key for customer entity set.
Candidate Key :
o “A Super key for which no subset is a super key is called a candidate key.”
o In other word, candidate key is a minimal super key
o A candidate key is also referred as ‘key’ only.
o A candidate key is sufficient to identify each and every entity uniquely within
an entity set.
o For example, combination of cid and contact_no is a super key for entity set
customer. But, only cid can alone identity entities uniquely. So, here
contact_no is a redundant attribute in super key. After removing all such
redundant attributes from a super key, the remaining attributes are
considered as a candidate key. So, here cid is a candidate key.
o Sometimes, there can be more than one candidate keys for the same entity
set.
o For example, for customer entity set, {cid} as well as { cname, address} are
candidate key.
Primary Key :
Example:
Consider a relationship set “depositor” having two entity set “Customer” and “Account”
The role of an entity can be denoted by labelling the lines that connect diamonds to
rectangles.
Multiple Relationships
An entity set that does not have sufficient attributes to form a primary key is called a weak
entity set.
An entity set having sufficient attributes to form a primary key is called a strong entity set.
For example, in above example of ternary relationship set, the entity set location is a weak
entity set. It depends on the entity set employee.