the er model defines the conceptual view of a database. it works around real-world entities and the associations among them. at view level, the er model is considered a good option for designing databases.
entity
an entity can be a real-world object, either animate or inanimate, 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.
attributes
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.
these attribute types can come together in a way like −
- simple single-valued attributes
- simple multi-valued attributes
- composite single-valued attributes
- composite multi-valued attributes
entity-set and keys
key is an attribute or collection of attributes that uniquely identifies an entity among entity set.
for example, the roll_number of a student makes him/her identifiable among students.
super key − a set of attributes (one or more) that collectively identifies an entity in an entity set.
candidate key − a minimal super key is called a candidate key. an entity set may have more than one candidate key.
primary key − a primary key is one of the candidate keys chosen by the database designer to uniquely identify the entity set.
relationship
the association among entities is called a relationship. for example, an employee works_at a department, a student enrolls in a course. here, works_at and enrolls are called relationships.
relationship set
a set of relationships of similar type is called a relationship set. like entities, a relationship too can have attributes. these attributes are called descriptive attributes.
degree of relationship
the number of participating entities in a relationship defines the degree of the relationship.
- binary = degree 2
- ternary = degree 3
- n-ary = degree
mapping cardinalities
cardinality defines the number of entities in one entity set, which can be associated with the number of entities of other set via relationship set.
one-to-one − one entity from entity set a can be associated with at most one entity of entity set b and vice versa.
one-to-many − one entity from entity set a can be associated with more than one entities of entity set b however an entity from entity set b, can be associated with at most one entity.
many-to-one − more than one entities from entity set a can be associated with at most one entity of entity set b, however an entity from entity set b can be associated with more than one entity from entity set a.
many-to-many − one entity from a can be associated with more than one entity from b and vice versa.