Draw Entity Relationship Diagram Example
After learning the steps of how to draw an enitity relationship diagram, we will create a demo ER diagram.
Let’s take an example of ER diagram for a bank through which we can learn how to design an ER and understand all the required methods.
Entity Relationship Diagram for BANK
We will follow the steps mentioned above, to draw entity relationship diagram for bank.
Defining Entities
A thing in the real world with an independent existence. It is may be an object with physical existence (ex: house, person) or with a conceptual existence (ex: course, job). The are represented by rectangle.
Entities for Bank are:
Bank, Branch, Employee, customer, loan, account.
Adding Attributes
Attributes are the kind of properties that describe the entities. They are represented by ovals.
Attributes for Bank are:
- For Bank Entity the Attributes are Bname, code.
- For Branch Entity the Attributes are Blocation, Bname.
- For Employee Entity the Attributes are Eid, Designation, salary.
- For Customer Entity the Attributes are Cid, Cname, Address, DOB.
- For Loan Entity the Attributes are Loan_no, amount, rate.
- For Account Entity the Attributes are acc_no, type.
Establishing Relationships
Entities have some relationships with each other. Relationships define how entities are associated with each other.
Let’s Establishing Relationships between them are:
- The Bank has branches.
- The Branch provides loan.
- The Employee works in branch.
- The Branch contains customers.
- The Customers has account.
- The Branch maintains account.
- The Customer avails loan.
Specifying Cardinality
Cardinality defines the numerical constraints on the relationships between entities. It is a notation that tells the ERD reader whether there are one, many or some combination of those factors between each entity.
1. One to One relationship(1:1)
In the entity relationship diagram, the one to one relationship means that single entity in one table is associated with single entity in another table. For example, one driver have only one license.
2. One to Many relationship(1:N)
One to many relationships means that single entity in one table is related to more than one entities in another table. For example, one bank has many branches.
3. Many to One(N:1)
Many-to-one relationship in entity relationship diagram means that multiple entities are related to only single entity in another table. For example, many developers works on single project.
4. Many to Many relationship(M:N)
Many to many relationship means that multiple entities in one table is associated with multiple entities in another table. For example, multiple customers have multiple accounts.
Specify cardinality for Bank:
- Bank and branch has One to Many relationship (a bank has multiple branches).
- Branch and loan has also One to Many relationship(a branch can provide many loans).
- Branch and employee has One to Many relationship(one branch has many employees).
- Branch and account has One to Many relationship(one branch has many accounts).
- Branch and customer has Many to Many relationship(multiple branches have multiple customers).
- Customer and account has Many to Many relationship(multiple customers have multiple accounts).
- Customer and loan has Many to Many relationships(multiple customers have multiple loans)
Identify Primary Keys
Primary keys are the unique identifier for each record in database table. It is denoted by an underline under the attribute name.
- The Primary key of Bank is code.
- The Primary key of Branch is branch_code.
- The Primary key of Employee is Eid.
- The Primary key of Customer is Cid.
- The Primary key of Loan is loan_no.
- The Primary key of Account is acc_no.
How to Draw Entity Relationship Diagrams (ERDs)
Entity Relationship Diagrams serve as valuable tools for designing complex systems and their relationships.
This article will go through the step-by-step process of designing an ER diagram and defining how entities, attributes, and relationships are defined. Entity relationship diagrams are important in database design and require a clear structure for all data.