Entity Relationship model is a technique that helps us model real-world systems in the form of software constructs. E-R Model defines the conceptual view of database. E-R diagram is a visual way used to represent data and how data is related to each other.
E-R Model Concepts
- Entity: An Entity is an object which has its own unique identity in real world. An Entity can be Person, Student, Teacher, Class, object etc. An Entity represents E in E-R Model.
- Entity Set: An entity set is a set of entities of the same type. For example, all students in a school can form an entity set called Student. Entity Set related to table in database. An entity set is represented by Rectangle in E-R diagram.
- Attribute: An attribute is a property or characteristic of entity. For example, Name, Gender, Address can be attributes of Student entity. An attribute is represented by using eclipse in E-R diagram. It corresponds to column in a table in database.
- Relationship: The relation or association between entities is called Relationship. A Relationship represents R in E-R Model. A relationship is represented by using diamond in E-R diagram. For example, Teacher teaches Student; here teaches is a relationship between entity Teacher and Student.
Types of Relationships
- One-to-One: In one-to-one (1:1) relationship, for a given occurrence of an entity (i.e. its value), there is exactly one occurrence of another entity. For example, a student can study in one class at a time.
- One-to-Many: In one-to-many (1:n) relationship, for a given occurrence of an entity (i.e. its value), there can be one or more occurrences of another entity. A student can enroll to many subjects.
- Many-to-Many: In many-to-many (m:n) relationship, there can be one or more values on both sides of a relationship. It means there can be multiple instances of both entities. For example, a teacher can teach multiple subjects, similarly a subject can have multiple teachers assigned to it.