The ER model defines the conceptual view of a database. It works around real-world entities and the
associations among them. At the view level, the ER model is considered a good option for designing databases.
Components of ER Diagram
An entity can be a real-world object, that can be easily identifiable. For example, in a school database, students, teachers, classes, and courses offered can be considered as entities. All these entities have some attributes or properties that give them their identity.
An entity set is a collection of similar types of entities. An entity set may contain entities with attribute sharing similar values.
For example, a Students set may contain all the students of a school; likewise a Teachers set may contain all the teachers of a school from all faculties. Entity sets need not be disjoint.
Entities are represented by means of their properties, called attributes. All attributes have values. For example, a student entity may have name, class, and age as attributes.
There exists a domain or range of values that can be assigned to attributes.
For example, a student’s name cannot be a numeric value. It has to be alphabetic.
A student’s age cannot be negative, etc.
Types of Attributes
- Simple attribute − Simple attributes are atomic values, which cannot be divided further. For example, a student’s phone number is an atomic value of 10 digits.
- Composite attribute − Composite attributes are made of more than one simple attribute. For example, a student’s complete name may have first_name and last_name.
- Derived attribute − Derived attributes are the attributes that do not exist in the physical database, but their values are derived from other attributes present in the database. For example, average_salary in a department should not be saved directly in the database, instead it can be derived. For another example, age can be derived from data_of_birth.
- Single-value attribute − Single-value attributes contain single value. For example − Social_Security_Number.
- Multi-value attribute − Multi-value attributes may contain more than one values. For example, a person can have more than one phone number, email_address, etc.
What is an Entity Relationship Diagram (ER Diagram)?
An ER diagram shows the relationship among entity sets. An entity set is 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 the database, so by showing the relationship among tables and their attributes, ER diagram shows the complete logical structure of a database. Let’s have a look at a simple ER diagram to understand this concept
A simple ER Diagram
In the following diagram, we have two entities Student and Teacher, and their relationship. The relationship between Student and teacher is many to one as a teacher can have many students however a student cannot study in multiple colleges at the same time. Student entity has attributes such as Stu_Id, Stu_Name & Stu_Addr and teacher entity has attributes such as tech_name & sub_code.
Geometric shapes and their meaning in an E-R Diagram.
- Rectangle: Represents Entity sets.
- Ellipses: Attributes.
- Diamonds: Relationship.
- Set Lines: They link attributes to Entity Sets and Entity sets to Relationship Set.
- Double Ellipses: Multivalued Attributes.
- Dashed Ellipses: Derived Attributes.
- Double Rectangles: Weak Entity Sets.
- Double Lines: Total participation of an entity in a relationship set.