ER Data Models
ER Data Models
Though there are other data models in use today, the Relational model is the
most used. Aside from the relational model, there are a variety of different
data models that we shall discuss in-depth in this article. Data Models in
DBMS include the following:
Hierarchical Model
This concept uses a hierarchical tree structure to organise the data. The
hierarchy begins at the root, which contains root data, and then grows into a
tree as child nodes are added to the parent node.
Network Model
The main difference between this model and the hierarchical model is that
any record can have several parents in the network model. It uses a graph
instead of a hierarchical tree.
Entity-Relationship Model
The real-world problem is depicted in visual form in this model to make it
easier for stakeholders to comprehend. The ER diagram also makes it very
simple for developers to comprehend the system.
Relational Model
The data in this model is kept in the form of a table that is two-dimensional.
All of the data is kept in the form of rows and columns. Tables are the
foundation of a relational paradigm.
Components of ER Diagram
Entity
Entity Type:
1. Strong Entity Type: It is an entity that has its own existence and is
independent.
The entity relationship diagram represents a strong entity type with the help
of a single rectangle. Below is the ERD of the strong entity type:
AD
.
2. Weak Entity Type: It is an entity that does not have its own existence
and relies on a strong entity for its existence.
The Entity Relationship Diagram represents the weak entity type using
double rectangles. Below is the ERD of the weak entity type:
In the above example, "Address" is a weak entity type with attributes such
as House No., City, Location, and State.
Attributes
Attributes are the properties that define the entity type. For example,
Roll_No, Name, DOB, Age, Address, and Mobile_No are the attributes
that define entity type Student. In ER diagram, the attribute is
represented by an oval.
Attribute
1. Key Attribute
The attribute which uniquely identifies each entity in the entity
set is called the key attribute. For example, Roll_No will be unique for
each student. The ER diagram represents the key attribute by an oval
with underlying lines.
Key Attribute
2. Composite Attribute
An attribute composed of many other attributes is called a
composite attribute. For example, the Address attribute of the student
Entity type consists of Street, City, State, and Country. In ER diagram,
the composite attribute is represented by an oval comprising of
ovals.
Composite Attribute
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For
example, Phone_No (can be more than one for a given student). In ER
diagram, a multivalued attribute is represented by a double oval.
Multivalued Attribute
4. Derived Attribute
An attribute that can be derived from other attributes of the entity
type is known as a derived attribute. e.g.; Age (can be derived from
DOB). In ER diagram, the derived attribute is represented by a dashed
oval.
Derived Attribute
Relationship Set
Unary Relationship
Cardinality
The number of times an entity of an entity set participates in a relationship set is known
as cardinality. Cardinality can be of different types:
1. One-to-One: When each entity in each entity set can take part
only once in the relationship, the cardinality is one-to-one. Let us
assume that a male can marry one female and a female can marry
one male. So the relationship will be one-to-one.
the total number of tables that can be used in this is 2.
One-to-One Cardinality
One to Many
3. Many-to-One: When entities in one entity set can take part only
once in the relationship set and entities in other entity sets can take
part more than once in the relationship set, cardinality is many to
one. Let us assume that a student can take only one course but one
course can be taken by many students. So the cardinality will be n to
1. It means that for one course there can be n students but for one
student, there will be only one course.
The total number of tables that can be used in this is 3.
Many-to-One Relationship
In this case, each student is taking only 1 course but 1 course has
been taken by many students.
4. Many-to-Many: When entities in all entity sets can take part more
than once in the relationship cardinality is many to many. Let us
assume that a student can take more than one course and one course
can be taken by many students. So the relationship will be many to
many.
the total number of tables that can be used in this is 3.
Many-to-Many
Example:
{STUD_NO, COURSE_NO} is a composite
candidate key for relation STUDENT_COURSE.
Table STUDENT_COURSE
TEACHER_N
STUD_NO O COURSE_NO
1 001 C001
2 056 C005
3. Super Key: The set of attributes that can uniquely identify a tuple
is known as Super Key. For Example, STUD_NO, (STUD_NO,
STUD_NAME), etc. A super key is a group of single or multiple keys
that identifies rows in a table. It supports NULL values.
Adding zero or more attributes to the candidate key
generates the super key.
A candidate key is a super key but vice versa is not true.
Example:
Consider the table shown above.
STUD_NO+PHONE is a super key.
Relation between Primary Key, Candidate Key, and Super Key
4. Alternate Key: The candidate key other than the primary key is
called an alternate key.
All the keys which are not primary keys are called alternate
keys.
It is a secondary key.
It contains two or more fields to identify two or more records.
These values are repeated.
Eg:- SNAME, and ADDRESS is Alternate keys
Example:
Consider the table shown above.
STUD_NO, as well as PHONE both,
are candidate keys for relation STUDENT but
PHONE will be an alternate key
(only one out of many candidate keys).
Primary Key, Candidate Key, and Alternate Key
5. Foreign Key: If an attribute can only take the values which are
present as values of some other attribute, it will be a foreign key to
the attribute to which it refers. The relation which is being referenced
is called referenced relation and the corresponding attribute is called
referenced attribute the relation which refers to the referenced
relation is called referencing relation and the corresponding attribute
is called referencing attribute. The referenced attribute of the
referenced relation should be the primary key to it.
It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
It combines two or more relations (tables) at a time.
They act as a cross-reference between the tables.
For example, DNO is a primary key in the DEPT table and a
non-key in EMP
Example:
1 005 C001
2 056 C005
It may be worth noting that, unlike the Primary Key of any given
relation, Foreign Key can be NULL as well as may contain duplicate
tuples i.e. it need not follow uniqueness constraint. For Example,
STUD_NO in the STUDENT_COURSE relation is not unique. It has been
repeated for the first and third tuples. However, the STUD_NO in
STUDENT relation is a primary key and it needs to be always unique,
and it cannot be null.