0% found this document useful (0 votes)
26 views21 pages

ER Data Models

The document discusses various data models in Database Management Systems (DBMS), highlighting the Hierarchical, Network, Entity-Relationship, Relational, and Object-Oriented models. It provides detailed explanations of the Entity-Relationship model, including its components such as entities, attributes, and relationships, along with symbols used in ER diagrams. Additionally, it covers different types of keys in the relational model, including candidate keys, primary keys, foreign keys, and composite keys.

Uploaded by

AMAN RAJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views21 pages

ER Data Models

The document discusses various data models in Database Management Systems (DBMS), highlighting the Hierarchical, Network, Entity-Relationship, Relational, and Object-Oriented models. It provides detailed explanations of the Entity-Relationship model, including its components such as entities, attributes, and relationships, along with symbols used in ER diagrams. Additionally, it covers different types of keys in the relational model, including candidate keys, primary keys, foreign keys, and composite keys.

Uploaded by

AMAN RAJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Types of Data Models in DBMS

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.

Object-Oriented Data Model


Both the data and the relationship are contained in a single structure that is
known as an object in this model. We can now store audio, video, pictures,
and other types of data in databases, which was previously impossible with
the relational approach (Although you can store video and audio in relational
DB, it is advised not to store them in the relational database).
Entity Relationship model

The Entity Relational Model is a model for identifying entities to be


represented in the database and representation of how those entities
are related. The ER data model specifies enterprise schema that
represents the overall logical structure of a database graphically.
The Entity Relationship Diagram explains the relationship among the
entities present in the database. ER models are used to model real-
world objects like a person, a car, or a company and the relation
between these real-world objects.

Symbols Used in ER Model


ER Model is used to model the logical view of the system from a data
perspective which consists of these symbols:
 Rectangles: Rectangles represent Entities in ER Model.
 Ellipses: Ellipses represent Attributes in ER Model.
 Diamond: Diamonds represent Relationships among Entities.
 Lines: Lines represent attributes to entities and entity sets
with other relationship types.
 Double Ellipse: Double Ellipses represent Multi-Valued
Attributes.
 Double Rectangle: Double Rectangle represents a Weak
Entity.
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among
Entities in a Database System.

Components of ER Diagram
Entity

An Entity may be an object with a physical existence – a particular


person, car, house, or employee – or it may be an object with a
conceptual existence – a company, a job, or a university course.

Entity Set: An Entity is an object of Entity Type and a set of all


entities is called an entity set. For Example, E1 is an entity having
Entity Type Student and the set of all students is called Entity Set. In
ER diagram, Entity Type is represented as:

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.

The relationship between a strong and a weak entity type is known as an


identifying relationship.

Using a double diamond, the Entity-Relationship Diagram represents a


relationship between the strong and the weak entity type.
Let us see an example of the relationship between the Strong entity type and
weak entity type with the help of ER Diagram:

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

The Complete Entity Type Student with its Attributes can be


represented as:

Entity and Attributes

Relationship Type and Relationship Set


A Relationship Type represents the association between entity types.
For example, ‘Enrolled in’ is a relationship type that exists between
entity type Student and Course. In ER diagram, the relationship type
is represented by a diamond and connecting the entities with lines.
Entity-Relationship Set

A set of relationships of the same type is known as a relationship set.


The following relationship set depicts S1 as enrolled in C2, S2 as
enrolled in C1, and S3 as registered in C3.

Relationship Set

Degree of a Relationship Set


The number of different entity sets participating in a relationship set
is called the degree of a relationship set.
1. Unary Relationship: When there is only ONE entity set
participating in a relation, the relationship is called a unary
relationship. For example, one person is married to only one person.

Unary Relationship

2. Binary Relationship: When there are TWO entities set


participating in a relationship, the relationship is called a binary
relationship. For example, a Student is enrolled in a Course.
Binary Relationship

3. n-ary Relationship: When there are n entities set participating in


a relation, the relationship is called an n-ary 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

Using Sets, it can be represented as:


Set Representation of One-to-One

2. One-to-Many: In one-to-many mapping as well where each entity


can be related to more than one relationship and the total number of
tables that can be used in this is 2.

One to Many

Using sets, one-to-many cardinality can be represented as:


Set Representation of 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

Using Sets, it can be represented as:


Set Representation of Many-to-One

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

Using Sets, it can be represented as:

Keys are one of the basic requirements of a relational database


model. It is widely used to identify the tuples(rows) uniquely in the
table. We also use keys to set up relations amongst various columns
and tables of a relational database.
Different Types of Keys in the Relational
Model
1. Candidate Key
2. Primary Key
3. Super Key
4. Alternate Key
5. Foreign Ke
6. Composite Key
1. Candidate Key: The minimal set of attributes that can uniquely
identify a tuple is known as a candidate key. For Example, STUD_NO
in STUDENT relation.
 It is a minimal super key.
 It is a super key with no repeated data is called a candidate
key.
 The minimal set of attributes that can uniquely identify a
record.
 It must contain unique values.
 It can contain NULL values.
 Every table must have at least a single candidate key.
 A table can have multiple candidate keys but only one
primary key (the primary key cannot have a NULL value, so
the candidate key with a NULL value can’t be the primary
key).
 The value of the Candidate Key is unique and may be null for
a tuple.
 There can be more than one candidate key in a relationship.
Example:
STUD_NO is the candidate key for relation STUDENT.
Table STUDENT
STUD_NO SNAME ADDRESS PHONE

1 Shyam Delhi 123456789

2 Rakesh Kolkata 223365796

3 Suraj Delhi 175468965


 The candidate key can be simple (having only one attribute)
or composite as well.

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

Note: In SQL Server a unique constraint that has a nullable


column, allows the value ‘null‘ in that column only once. That’s why
the STUD_PHONE attribute is a candidate here, but can not be a ‘null’
value in the primary key attribute.

2. Primary Key: There can be more than one candidate key in


relation out of which one can be chosen as the primary key. For
Example, STUD_NO, as well as STUD_PHONE, are candidate keys for
relation STUDENT but STUD_NO can be chosen as the primary key
(only one out of many candidate keys).
 It is a unique key.
 It can identify only one tuple (a record) at a time.
 It has no duplicate values, it has unique values.
 It cannot be NULL.
 Primary keys are not necessarily to be a single column; more
than one column can also be a primary key for a table.
Example:

CREATE TABLE Persons (


ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);

CREATE TABLE Persons (


ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CONSTRAINT PK_Person PRIMARY KEY (ID,LastName)
);
STUDENT table -> Student(STUD_NO, SNAME,
ADDRESS, PHONE) , STUD_NO is a primary key
Table STUDENT
STUD_NO SNAME ADDRESS PHONE

1 Shyam Delhi 123456789

2 Rakesh Kolkata 223365796

3 Suraj Delhi 175468965

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:

CREATE TABLE Orders (


OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
Refer Table STUDENT shown above.
STUD_NO in STUDENT_COURSE is a
foreign key to STUD_NO in STUDENT relation.
Table STUDENT_COURSE
TEACHER_N
STUD_NO O COURSE_NO

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.

Relation between Primary Key and Foreign Key

6. Composite Key: Sometimes, a table might not have a single


column/attribute that uniquely identifies all the records of a table. To
uniquely identify rows of a table, a combination of two or more
columns/attributes can be used. It still can give duplicate values in
rare cases. So, we need to find the optimal set of attributes that can
uniquely identify rows in a table.
 It acts as a primary key if there is no primary key in a table
 Two or more attributes are used together to make a
composite key.
 Different combinations of attributes may give different
accuracy in terms of identifying the rows uniquely.
Example:
FULLNAME + DOB can be combined
together to access the details of a student.

Different Types of Keys


Many-to-Many Set Representation

In this example, student S1 is enrolled in C1 and C3 and Course C3 is


enrolled by S1, S3, and S4. So it is many-to-many relationships.

You might also like