What is an ER diagram?
An Entity-Relationship (ER) diagram expresses the logical structure of a database by showing the relationships between entity sets in a system. ER diagrams are widely used because they help structure information stored in a database and can be directly translated into tables.
Components
The following are the major components of an ER diagram:
-
Entity
An entity is a real-world object. It may or may not have a physical existence. Examples include person John and his bank account.
-
Entity Set
An entity set is a collection of similar entities. Examples include a group of people or a bank. An entity set is represented by a rectangle in an ER diagram.
-
Attribute
An attribute is the property of an entity. Examples include name, age, etc. An attribute is represented by an oval in an ER diagram.
-
Relationship
A relationship is an association between two or more entity sets. A relationship is represented by a diamond in an ER diagram.
-
Cardinality
Cardinality defines the attributes of a relationship using numbers. It includes:
-
One-to-one relationship: An entity in entity set “a” is associated with, at most, one entity in entity set “B”.
-
One-to-many relationship: An entity “a” is associated with more than one entity in “B”.
-
Many-to-one relationship: Many entities in “a” are associated with an entity in “b”.
-
Many-to-many relationship: Many entities in “a” are associated with many entities in “b”.
-
The following illustration shows an ER diagram:
Free Resources