ER Model : Basic Concepts
Entity relationship model defines the conceptual view of database. It works around real world entity and association among them. At view level, ER model is considered well for designing databases.
A real-world thing either animate or inanimate that can be easily identifiable and distinguishable. For example, in a school database, student, teachers, class and course offered can be considered as entities. All entities have some attributes or properties that give them their identity.
An entity set is a collection of similar types of entities. Entity set may contain entities with attribute sharing similar values. For example, Students set may contain all the student of a school; likewise Teachers set may contain all the teachers of school from all faculties. Entities sets need not to 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, age as attributes.
There exist 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 attributes are atomic values, which cannot be divided further. For example, student's phone-number is an atomic value of 10 digits.
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 attributes are attributes, which do not exist physical in the database, but there values are derived from other attributes presented in the database. For example, average_salary in a department should be saved in database instead it can be derived. For another example, age can be derived from data_of_birth.
Single valued attributes contain on single value. For example: Social_Security_Number.
Multi-value attribute may contain more than one values. For example, a person can have more than one phone numbers, email_addresses 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, roll_number of a student makes her/him identifiable among students.
Super Key: Set of attributes (one or more) that collectively identifies an entity in an entity set.
Candidate Key: Minimal super key is called candidate key that is, supers keys for which no proper subset are a superkey. An entity set may have more than one candidate key.
Primary Key: This is one of the candidate key chosen by the database designer to uniquely identify the entity set.
The association among entities is called relationship. For example, employee entity has relation works_at with department. Another example is for student who enrolls in some course. Here, Works_at and Enrolls are called relationship.
Relationship of similar type is called 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 an relationship defines the degree of the relationship.
Binary = degree 2
Ternary = degree 3
n-ary = degree
Cardinality defines the number of entities in one entity set which can be associated to 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 but from entity set B one entity 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 but one 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.