An Entity Relationship model (ER model) shows the structure of a database with the help of a diagram, called as Entity Relationship Diagram or ER Diagram. An ER model is considered as a design or blueprint of a database that can be implemented later as a functioning database. The major components of E-R model are: entity, attribute, entity set and relationship set.
Entity Relationship Diagram or ER Diagram
An ER diagram shows the relationship among the entity sets.
An entity set is considered as a group of similar entities and these entities can have attributes. In terms of DBMS, an entity is a table or attribute of a table in database. An ER diagram shows the complete logical structure of the database.
Now let’s build an Entity relationship diagram for a student in a college or a university step by step by understanding all the components of the ER diagram.
Components of a ER Diagram
The main and basic components of a ER diagram are:
An Entity can be an object with a physical existence – a person, bike, house, or an employee. It can also be an object with a conceptual existence – a company, a job, or a course in a college.
An entity is denoted by a Rectangle.
An entity set is a set of all the entities. For example, let S be an entity with entity type Student, then set of all students is known as Entity set.
An entity that cannot be uniquely identified by its own attributes and depends on the relationship with other entity is known as a weak entity.
A weak entity is denoted by double Rectangle.
An attribute is simply a property of the entity. For example, Name of a student is an attribute for the entity Student.
An attribute is denoted by an ellipse.
There are four types of attributes.
- Key Attribute
- Composite Attribute
- Multi valued Attribute
- Derived Attribute
A key attribute uniquely identifies an entity in a entity set. For example, roll_no of a student uniquely identifies a student among all the students in a college, So roll_no of a student can be a key attribute for a entity set Student.
Key attributes are denoted by ellipses with an underline to the attribute.
An attribute from which other attributes can be derived is known as a composite attribute. For example, Address of a student has other attributes like door_no, Street, City, State. So address of a student can be considered as a composite attribute for entity set Student.
Composite attributes are also denoted by ellipses but have other attributes derived from them.
Multi valued Attribute
A multi valued attribute is an attribute that has more than one values. For example, a student can have more than one phone numbers. So, phone number of a student can be considered as a multi valued attribute for the entity set Student.
A multi valued attribute is denoted by double ellipses.
Derived attributes are the attributes that can be derived from other attributes. For example, age of a student can be derived from the date of birth of a student. Hence age can be considered as a derived attribute of the student entity set.
A derived attribute is denoted by a dotted ellipse.
A relationship is considered as the relation between two or more entities. For example, “enrolled in” is the relationship between the entities student and course.
A relationship is denoted by diamond or rhombus shape.
Relationship set is a set of relationships of same type. For example, student A is enrolled in course Java, student B is enrolled in course DBMS, student C is enrolled in course C++. The following diagram represents relationship set.
Degree of Relationship
Degree of a relationship is the number of different entity sets participating in a relationship. There are different types of relationship sets.
If only a single entity set is participating in a relationship then it is known as a unary relationship. For example, student A does friendship with student B.
If two entity sets are participating in a relationship then it is known as a binary relationship. For example a student is enrolled in a course.
If more than two entity sets are participating in a relationship then it is called as n-ary relationship.
The number of entities of an entity set participating in a relationship is known as cardinality. There are different types of cardinalities.
- one to one
- many to one
- many to many
One to One
If only one entity of each entity set participates in a relationship then it is called one to one cardinality. For example, student A is enrolled in course A.
Many to One
If in a relationship, more than one entities of an entity set and only one entity of another entity set is participating in a relationship then it is called as many to one relationship. For example, Both students A&B are enrolled in course java and student C is enrolled in course DBMS.
Many to Many
If in a relationship, more than one entities of each entity set are participating then the relationship is known as many to many relationship. For example, student A is enrolled in courses java and DBMS and student B is enrolled in courses java and DBMS.
Also read: Data Models in DBMS