DATA MODEL
A data model within a Database Management System (DBMS) serves as an abstract
representation of how data gets structured and organized within a database.
It outlines the logical arrangement of data and the connections between various data
components.
Data models play a crucial role in comprehending and shaping databases, acting as a vital
link between real-world entities and the actual storage of data within the database.
DATA MODEL
Types of Data Model
Hierarchical Data Model
Network Data Model
Relational Data Model
Entity-Relationship Model (ER Model)
Object-Oriented Data Model
NoSQL Data Models
TYPES OF DATA MODEL
Hierarchical Data Model: This model portrays data in a
manner resembling a tree structure, where each record
maintains a parent-child relationship. Its primary
application lies in older database systems.
School
department Infrastructure
Teacher Student Staff
TYPES OF DATA MODEL
Network Data Model: This model shares similarities with
the hierarchical approach, permitting records to hold
multiple parent-child relationships. It adopts a structure
akin to a graph, offering more flexibility compared to the
hierarchical model.
Playground
Lab School
Student
TYPES OF DATA MODEL
Relational Data Model: Organizing data into tables
(known as relations) consisting of rows and columns
characterizes the relational model. It stands as the most
prevalent data model, rooted in the principles of set
theory, and relies on Structured Query Language (SQL) for
data manipulation.
ID Name Place
Primary key DELHI Row/tuple
1 Rahul
2 Raj KOLKATA
3 Riti MUMBAI
Column/Attribute
TYPES OF DATA MODEL
Entity-Relationship Model (ER Model): Utilized for
crafting relational databases, the ER model represents
data through entities (objects), attributes (entity
properties), and relationships connecting these entities.
Study Student Name
Student name
Relationship Entity Attribute
TYPES OF DATA MODEL
Object-Oriented Data Model: Extending the principles of
object-oriented programming into the database domain,
this model depicts data as objects complete with
attributes and methods, fostering support for inheritance
and encapsulation.
NoSQL Data Models: NoSQL databases encompass a
diverse array of data models, such as document-oriented
(e.g., MongoDB), key-value (e.g., Redis), column-family (e.g.,
Cassandra), and graph (e.g., Neo4j). These models are
designed to offer scalability and flexibility when handling
extensive volumes of unstructured or semi-structured
data.
DATA INDEPENDENCE
Data independence is a fundamental concept within
database design and management, emphasizing the
distinction between the logical and physical dimensions
of data storage and administration in a database
management system (DBMS). This principle yields
various benefits, such as enhanced flexibility, heightened
security, and simplified maintenance.
DATA INDEPENDENCE
There are three levels of Abstraction
view 1 View
DBMS level
Introduction
Logical Data
Independence
logical level
Physical Data
Independence
physical level
ESSENTIAL COMPONENTS OF TABLES
Row/Tuple - Rows, also known as records or tuples, represent individual entries or
instances of data within the table.
Cardinality - No of rows in a table
Column/Attribute - Columns represent the attributes of the data being stored and are
named to describe the information they hold (e.g., "ID," "Name," "Age").
Degree - No of Columns in a ta in a tableble
ESSENTIAL COMPONENTS OF TABLES
ID Name Place
1 Rahul DELHI
2 Raj KOLKATA
3 Riti MUMBAI
ESSENTIAL COMPONENTS OF TABLES
Constraints - Constraints define rules or conditions that must be satisfied by the data in
the table.
Common constraints include uniqueness, nullability, default values, etc.
Unique constraint: Ensures values in a column are unique across the table.
Not null constraint: Ensures a column cannot have a null value.
Check constraint: Enforces a condition to be true for each row.
Default constraint: Provides a default value for a column if no value is specified.
Keys - A primary key is a unique identifier for each record in the table. It ensures that each
row can be uniquely identified and accessed within the table.
A foreign key is a field in a table that refers to the primary key of another table. It
establishes relationships between tables.
VIEWS IN DBMS
View is a virtual table that is derived from one or more underlying tables.
This means that it doesn't physically store data but rather provides a logical
representation of data.
Customer DB
ID. NAME phn Address Pin Age
1 Raj 456 blr 123 18
2 Ravi 123 delhi 124 21
3 Ram 789 hyd 345 22
KEYS IN DBMS
Keys in DBMS make sure of data integrity, uniqueness, and the quick retrieval of
information. Key is a attribute in table
Types of keys :
Candidate Key
Primary Key
Foreign Key
Super Key
KEYS IN DBMS
Candidate Key : A candidate key refers to a group of attributes capable of uniquely
identifying a record within a table. Among these, one is selected to serve as the
primary key.
Ex- For student possible attributes for candidate key could be
Student<ID, Roll no , Aadhar Card>
Age Name Hometown
20 Rahul KOLKATA
21 Raj KOLKATA
20 Riti DELHI
KEYS IN DBMS
Primary Key : A primary key is a key which uniquely identifies each record in a table.
It ensures that each tuple or record can be uniquely identified within the table.
It is always Unique+ Not null
ID Name Hometown
123 Rahul KOLKATA
245 Raj KOLKATA
434 Riti DELHI
KEYS IN DBMS
Foreign Key : A foreign key is a field in a table that refers to the primary key in
another table. It establishes a relationship between two tables.
Student Subject
(Base/referenced table) (referencing table)
Roll Roll
Name Hometown Name subject
no no
1 Rahul KOLKATA 1 Rahul Maths
2 Raj KOLKATA 2 Raj SST
3 Riti DELHI 3 Riti Science
Primary key Foreign key
KEYS IN DBMS
Referenced table - Table having primary key (pk)
Referencing table- Table having foreign key(fk)
Student Subject
(Base/referenced table) (referencing table)
Roll Roll subject
Name Hometown subject
no no id
1 Rahul KOLKATA 1 s1 Maths
2 Raj KOLKATA 2 s2 SST
3 Riti DELHI 3 s3 Science
Primary key Foreign key
KEYS IN DBMS
Referential Integrity in Foreign key
Referential integrity is an important concept in foreign key. We
always say foreign key maintains referential integrity.
Referential integrity ensures that the relationships between
tables remain accurate, consistent, and meaningful
within a relational database.
KEYS IN DBMS
Referential Integrity in Foreign key
Now consider there are two tables one is refrencing and other is
refrenced table .
Lets see how some operations like insert, update and delete works
here.
KEYS IN DBMS
Refrential Integrity in Foreign key
Insertion in Referenced/base table
No violation
KEYS IN DBMS
Refrential Integrity in Foreign key
Deletion in Referenced/base table
May cause violation if the coressponding data is present in
refrencing table.
KEYS IN DBMS
Refrential Integrity in Foreign key
If a record in referenced table is deleted or updated , the
corresponding records in the referencing table should be deleted or
updated to maintain the integrity of the relationship.
We using action like "CASCADE DELETE" for the same. Also we can
set null for the values deleted.
KEYS IN DBMS
Refrential Integrity in Foreign key
Updation in Referenced/base table
May cause violation if the coressponding data is present in
refrencing table. We can using action like "CASCADE UPDATE”.
KEYS IN DBMS
Refrential Integrity in Foreign key
Insertion in Referencing table
May cause violation
KEYS IN DBMS
Refrential Integrity in Foreign key
Deletion in Referencing table
No violation
KEYS IN DBMS
Refrential Integrity in Foreign key
Updation in Referencing table
No issues untill we are updating foreign key attribute
Voilation would be caused on updating
INTEGRITY CONSTRAINT IN DBMS
Integrity constraints help to ensure that data remains reliable and
meaningful throughout its lifecycle.
Types of Integrity Constraint:
Domain Integrity Constraint
Entity Integrity Constraint
Referential Integrity Constraint
Key Constraint
Check Constraint
Null Constraint
Unique Constraint
Default Constraint
INTEGRITY CONSTRAINT IN DBMS
Domain Integrity Constraint
It ensures the validity and appropriateness of data values
(i.e valid data types, ranges, and formats for columns)
within a specific column or attribute of a table.
Ex-> Check for date column so that it contains valid date values
INTEGRITY CONSTRAINT IN DBMS
Entity Integrity Constraint
It ensures that each row/record in a table is uniquely identified
by a primary key.
It also helps in preventing duplicate or null values in the primary
key.
INTEGRITY CONSTRAINT IN DBMS
Referential Integrity Constraint
It ensures that values in a foreign key column match with the
values in the corresponding primary key column in another table.
INTEGRITY CONSTRAINT IN DBMS
Key Constraint
It ensures uniqueness for the primary key.
INTEGRITY CONSTRAINT IN DBMS
Check Constraint
It checks for a condition that each row in a table must satisfy.
If the condition is not met, the insertion or update of the row is
rejected.
INTEGRITY CONSTRAINT IN DBMS
Null Constraint
It determines whether a column in a table can have null (i.e.,
missing or unknown) values or not.
INTEGRITY CONSTRAINT IN DBMS
Unique Constraint
It ensures that values in a specified column or combination of
columns are unique across a table.
This constraint prevents duplicate values from being inserted
into the specified column(s), maintaining data consistency and
integrity.
INTEGRITY CONSTRAINT IN DBMS
Default Constraint
It ensures a default value for a column, which is used if no other
value is provided
SUPER KEY IN DBMS
It is a set of one or more attributes (columns) that can uniquely
identify a tuple (a row) in a relation (table).
Superset of any candidate key.
A super key becomes a candidate key if it is minimal (i.e. no
proper subset of it can uniquely identify a tuple).
ER MODEL IN DBMS
Introduction to ER Model
Entity Attributes Relationship
Things/Object Properties of entity association among entities
Ex-person Ex-name,age Ex-Works for
ER MODEL IN DBMS
The Entity-Relationship (ER) model stands as a prevalent
conceptual modeling approach within the realm of database
design.
Its primary role is to offer a visual representation of a
database's architecture by illustrating the entities, their
respective attributes, and the interconnections between
them.
In the process of database design, the ER model holds
significant importance, aiding in the development of an
efficient and systematically structured database schema.
ER MODEL IN DBMS
ER MODEL
ATTRIBUTE RELATIONSHIP
ENTITY
Simple Attribute one to one
Strong Entity
Composite Attribute one to many
Weak Entity
Single valued Attribute many to one
Multivalued Attribute many to many
Stored Attribute
Derived Attribute
Composite Attribute
ER MODEL IN DBMS
Symbols used in ER Model
Figures Symbols For what
Rectangle Entity
Ellipse Attribute
Diamond Relationship
Attribute to entity
Line
relationship
Multivalued
Double ellipse
attributes
Double rectangle Weak Entity
ER MODEL IN DBMS id
Name
Attributes
Professor teaches Student
Entity Entity
Relationship subject
Student name
ER MODEL IN DBMS
Entity
An entity is something from the real world, like a person, place,
event, or idea. Each entity has specific features or traits that
describe it.
ER MODEL IN DBMS
Types of Entity
Strong Entity Weak Entity
Person Entity Dependent Entity
ER MODEL IN DBMS
Types of Entity
Strong Entity: A strong entity is an entity that has its own unique
identifier (primary key) and is not dependent on any other entity
for its existence within the database. Strong entities stand alone
and have their own set of attributes.
Ex-Person
Weak Entity: A weak entity is an entity that doesn't have a
primary key of its own. It relies on a related strong entity (known
as the "owner" entity) for its identity. The weak entity's existence
is defined by being related to the owner entity.
ex- dependent
ER MODEL IN DBMS
Attribute
Attributes represent properties or characteristics of an entity or
relationship.
They provide information about the entities and relationships in
the database.
ER MODEL IN DBMS
Types of Attributes
Simple Attribute
A simple attribute is atomic and cannot be divided any further.
Ex- First Name
ER MODEL IN DBMS
Types of Attributes
Composite Attribute
A composite attribute is made up of several smaller parts, where
each part represents a piece of the whole attribute. In simpler
terms it is composed of attributes which can be divided further.
Ex- Name( First Name, lastName)
ER MODEL IN DBMS
Types of Attributes
Single Valued Attribute
A single-value attribute is an attribute that holds a single value
for each entity
Ex- Age
ER MODEL IN DBMS
Types of Attributes
Multivalued Attribute
A multi-valued attribute in a database is an attribute that can
hold multiple values for a single entity.
Ex- Address (permanent, residential)
ER MODEL IN DBMS
Types of Attributes
Stored Attribute
Attribute that is stored as a part of a database record.
Ex- Date of birth
ER MODEL IN DBMS
Types of Attributes
Derived Attribute
A derived attribute is derived from other attributes within the
database.
Ex- Age derived from dob
ER MODEL IN DBMS
Types of Attributes
Complex Attribute
A complex attribute is an attribute that is made up of multiple
smaller attributes
Ex- Name(Composite) FirstName
Middle Name (Simple attribute)
lastName
ER MODEL IN DBMS
Relationship in ER Model
Relationship in ER MODEL is the connection between entities (tables) based on
related data.
Types of Relationship
Strong Relationship Weak Relationship
ER MODEL IN DBMS
Strong Relationship
A strong relationship exists when two entities are highly dependent on each other,
and one entity cannot exist without the other.
Ex-
ER MODEL IN DBMS
Weak Relationship
A weak relationship, on the other hand, exists when two entities are related, but one
entity can exist without the other.
Ex-
ER MODEL IN DBMS
Degree in DBMS
A degree in dbms refers to the number of attributes / columns that a
relation/table has.
ER MODEL IN DBMS
Types of Degree
Degree Name Defination
1 Unary Degree A relation with a single attribute
2 Binary Degree A relation with two attributes
3 Ternary Degree A relation with three attributes
n n-ary Degree A relation with more than three attributes n>3
ER MODEL IN DBMS
Null value : In databases, a null value can occur for various
reasons
Not Needed Information: Sometimes, some details are asked, but
they don't apply to everyone. For instance, asking for a "Spouse
Name" from someone who isn't married.
Don't Know the Answer: Every now and then, we're asked a
question, but we don't have an answer yet.
Forgot to Fill In: Like when you're filling out a form, and you
accidentally miss putting in some important information.
ER MODEL IN DBMS
Types of relationship in dbms (Based on degree)
There are 4 types of relationship:
one to one (1-1)
one to many (1-N)
many to one (N-1)
many to many (N-N)
ER MODEL IN DBMS
Types of Relationship(Cardinality)
1 to 1 Relationship(1:1)
A complex attribute is an attribute that is made up of multiple smaller attributes
Student Enrolls Course
ER MODEL IN DBMS
Types of Relationship(Cardinality)
1 to 1 Relationship(1:1)
Student Enrolls Course
sid sname sage sid cid edate cid cname cprof
s1 ram 14 s1 c1 jan c1 phy saurav
s2 raj 15 s2 c2 feb c2 math sanjeev
s3 riti 16 s3 c3 mar c3 bio sumit
ER MODEL IN DBMS
sid sname sage sid cid edate cid cname cprof
s1 ram 14 s1 c1 jan c1 phy saurav
s2 raj 15 s2 c2 feb c2 math sanjeev
s3 riti 16 s3 c3 mar c3 bio sumit
sna sag cid cname cprof
sid cid edate
me e
c1 phy saurav
s1 ram 14 c1 jan
c2 math sanjeev
s2 raj 15 c2 feb
c3 bio sumit
s3 riti 16 c3 mar
ER MODEL IN DBMS
Types of Relationship
1 to Many Relationship(1:N)
A database model where one entity (record) on one side of the
relationship is associated with multiple entities (records) on the
other side
Author Reads Books
ER MODEL IN DBMS
Types of Relationship
1 to Many Relationship(1:N)
Author Reads Books
aid aname aage aid bid bdate bid bname btype
a1 ram 14 a1 b1 jan b1 ab fiction
a2 raj 15 a2 b2 feb b2 cd thrill
a3 riti 16 a1 b3 mar b3 ef drama
ER MODEL IN DBMS
aid aname aage aid bid bdate bid bname btype
a1 ram 14 a1 b1 jan b1 ab fiction
a2 raj 15 a2 b2 feb b2 cd thrill
a3 riti 16 a1 b3 mar b3 ef drama
aid aname aage
bid bname btype aid bdate
a1 ram 14
b1 ab fiction a1 jan
a2 raj 15
b2 cd thrill a2 feb
a3 riti 16
b3 ef drama a1 mar
ER MODEL IN DBMS
Types of Relationship
Many to 1 Relationship(N:1)
A database model where multiple entities (records) on one side
of the relationship are associated with a single entity (record) on
the other side.
ER MODEL IN DBMS
Types of Relationship
Many to 1 Relationship(N:1)
works
Employees Department
ER MODEL IN DBMS
Types of Relationship
Many to many Relationship(N:N)
A database model where multiple entities (records) on one side
of the relationship are associated with multiple entities on the
other side.
Enrolls
Students Courses
ER MODEL IN DBMS
Types of Relationship
Many to many Relationship(N:N) Students Enroll
Courses
sid sname sage sid bid edate cid cname cprof
s1 ram 14 s1 c1 jan c1 phy saurav
s2 raj 15 s2 c2 feb c2 math sanjeev
s3 riti 16 s3 c3 mar c3 bio sumit
ER MODEL IN DBMS
Person Pan
ER MODEL IN DBMS
Person Mobile Num
ER MODEL IN DBMS
Book Author
ER MODEL IN DBMS
Student Course
ER MODEL IN DBMS
Participation Constraints
Participation Constraints in an ER model define whether every
entity in one group must be connected with at least one entity in
another group or if the connection is optional.
ER MODEL IN DBMS
Types of Participation Constraints
Total Participation(Mandatory)
In a total participation constraint, each entity in a participation set must be
associated with at least one entity in the related entity set.
works
Employees Department
ER MODEL IN DBMS
Types of Participation Constraints
Partial Participation(Optional)
In a partial participation constraint, entities in the participating entity set may or
may not be associated with entities in the related entity set.
works
Employees Department
ER MODEL IN DBMS
Extended ER features
Why do we need?
We design ER model for relationship betwn entities
In real-world the data may exhibit some hierarchical relationships, and the
EER model provides mechanisms to represent these relationships
accurately which helps in code reusabilitilty, ensuring data integrity and
consistency and lower the complexity.
ER MODEL IN DBMS
Extended ER features
Specialization Generalization
Aggregation
ER MODEL IN DBMS
Extended ER features
Specialization
Specialization in the ER model is like categorizing entities based on common
features.
A "Supertype" groups entities with shared attributes and relationships, while
"Subtypes" have their own unique attributes and relationships. It's a way to organize
data efficiently. It is a Top-Down approach.
We have is-a relationship between superclass and subclass.
ER MODEL IN DBMS
Extended ER features
Generalization
Generalization is like finding things that are alike and putting them into a big group to
represent what they have in common. It helps make things simpler and organized.
It is a Bottom-Up approach.
We have is-a relationship between subclass and superclass.
ER MODEL IN DBMS
Extended ER features
Inheritance
Attribute Participation
ER MODEL IN DBMS
Extended ER features
Aggregation
Aggregation is like stacking things on top of each other to create a structure.
It is used to create a hierarchical structure in data modeling, showing how a higher-
level entity is composed of lower-level entities.
Abstraction is employed to view relationships from a more general perspective,
focusing on a higher-level entity.
ER MODEL IN DBMS
Steps to draw an ER model
1. Recognize entities.
2. Specify entity characteristics/attributes.
3. Discover connections/relationships(also contraints like
mapping/participation)
4. Define the connection type (how entities connect)/cardinality.
5. Construct an ERD (Entity-Relationship Diagram).
6. Annotate relationships and attributes.
7. Review and refine the model.
8. Document the model.
9. Validate with stakeholders.
10. Implement the database schema.
ER MODEL IN DBMS
ER Model of Instagram
Lets start with what is instagram?
Instagram is a social media platform that allows users to share photos and
videos.
ER MODEL IN DBMS
ER Model of Instagram
Now what all things we can do on instagram?
Create our profile
Add profile picture and details
Connect with friends
Upload a post
Like and comment on post
Share stories
and much more
ER MODEL IN DBMS
ER Model of Instagram
Lets start with all the steps needs to draw an ER diagram.
Step-1 : Recognize entities sets
Entities
userLikes
userProfile
userFriends
userPost
userLogin
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
1. userProfile (user ID, username, email, profile pic)
user ID- primary key
userName- composite attribute
email - single valued attribute
profile pic - single valued attribute
dob- stored attribute
age- derived attribute
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
2. userFriends (followerID, followerName, userID)
followerID- primary key
followerName - single valued attribute
userID - single valued attribute
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
3. userPost (post ID, caption, image, video, likesCount, timestamp)
post ID- primary key
caption - single valued attribute
image - multi valued attribute
video - multi valued attribute
likesCount - single valued attribute
timestamp - single valued attribute
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
4. userLogin (login ID,loginUserName,loginPassword)
login ID- primary key
loginUserName - single valued attribute
loginPassword - multi valued attribute
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
4. userLikes (postID, userID)
postID- primary key
userID - single valued attribute
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Discover connections/relationships(also contraints like
mapping/participation)
1.userProfile have userFriends (n:n)
2. userProfile have userPost (1:n) userPost will always be associated to a userProfile
therefore total participation
3. userProfile has userLogin (1:1)
4. userProfile has userLikes (1:n) userLikes will always be associated to a userProfile
therefore total participation
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Discover connections/relationships(also contraints like
mapping/participation)
5. userFriends have userPost (1:n) userPost will always be associated to a userProfile
therefore total participation
6. userFriends has userLogin (1:1)
7. userFriends has userLikes (1:n) userLikes will always be associated to a userProfile
therefore total participation
RELATIONAL MODEL
It is a way of organizing data in tables.
Some terms used in relational model
1. Table - Relation
2. Row - Tuple
3. Column - Attribute
4. Record - Each row in a table
5. Domain - The type of value an attribute can hold
6. Degree - No. of columns in a relation
7. Cardinality - No of tuples
RELATIONAL MODEL
Relational model is all about:
Data being organized into tables
Establishing Relationships between tables using Foreign key
Maintaining data Integrity
A flexible and efficient way to store(SQL) and retrieve data
RELATIONAL MODEL
In relational model we take care of different things like:
1. Maintaining integrity constraints like domain, entity, referential integrity.
2. The values to be atomic i.e can’t be divided further.
3. Each row must be unique, here keys comes into picture i.e candiate, super,
primary etc
CONVERT AN ER MODEL TO RELATIONAL MODEL
Converting an Entity-Relationship (ER) model to a relational model involves several
steps:
Step 1: Identify the entities - List down all the entities like strong and weak.
Person has Address
Strong entity Weak entity
Person (id, name , age) -> id (p.k)
Address (id , flatno, street, city)->id+flatno (p.k) , id (f.k)
CONVERT AN ER MODEL TO RELATIONAL MODEL
Step 2: Identify the attributes - For each entity, identify its attributes which
becomes a column in the table.
Multivalued attribute
Composite attribute
CONVERT AN ER MODEL TO RELATIONAL MODEL
Step 3: Key selection - Choose the primary key for each table, for some it can be
in form of composite key (Weak entity)
Step 4: If entities have relationship break it down and the reduce the tables if
possible.
1. 1-1 Relationship : 2 tables , P.K can lie on any side
2. 1-Many Relationship : 2 tables , P.K can lie on many side
3. Many -1 relationship : 2 tables , P.K can lie on many side
4. Many-Many relationship : 3 tables , P.K lie in the relation table having pk from
both the table acting as fk
CONVERT AN ER MODEL TO RELATIONAL MODEL
Step 3: Key selection - Choose the primary key for each table, for some it can be
in form of composite key (Weak entity)