L2 Data Models
L2 Data Models
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
School
department Infrastructure
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
2 Raj KOLKATA
3 Riti MUMBAI
Column/Attribute
TYPES OF DATA MODEL
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.
view 1 View
DBMS level
Introduction
Logical Data
Independence
logical level
Physical Data
Independence
physical level
ESSENTIAL COMPONENTS OF TABLES
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").
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
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
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
Student Subject
(Base/referenced table) (referencing table)
Roll Roll
Name Hometown Name subject
no no
Student Subject
(Base/referenced table) (referencing table)
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
No violation
KEYS IN DBMS
Refrential Integrity in Foreign key
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
No violation
KEYS IN DBMS
Refrential Integrity in Foreign key
Ex-> Check for date column so that it contains valid date values
INTEGRITY CONSTRAINT IN DBMS
Key Constraint
Check Constraint
Null Constraint
Unique Constraint
Default Constraint
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
Rectangle Entity
Ellipse Attribute
Diamond Relationship
Attribute to entity
Line
relationship
Multivalued
Double ellipse
attributes
Attributes
Professor teaches Student
Entity Entity
Relationship subject
Student name
ER MODEL IN DBMS
Entity
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
Attribute
Simple Attribute
Composite Attribute
Ex- Age
ER MODEL IN DBMS
Types of Attributes
Multivalued Attribute
Stored Attribute
Derived Attribute
Complex Attribute
Relationship in ER Model
Types of Relationship
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
Types of Degree
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
1 to 1 Relationship(1:1)
1 to 1 Relationship(1:1)
Student Enrolls Course
c3 bio sumit
s3 riti 16 c3 mar
ER MODEL IN DBMS
Types of Relationship
1 to Many Relationship(1:N)
1 to Many Relationship(1:N)
b3 ef drama a1 mar
ER MODEL IN DBMS
Types of Relationship
Many to 1 Relationship(N:1)
Many to 1 Relationship(N:1)
works
Employees Department
ER MODEL IN DBMS
Types of Relationship
Enrolls
Students Courses
ER MODEL IN DBMS
Types of Relationship
Person Pan
ER MODEL IN DBMS
Book Author
ER MODEL IN DBMS
Student Course
ER MODEL IN DBMS
Participation Constraints
works
Employees Department
ER MODEL IN DBMS
Types of Participation Constraints
Partial Participation(Optional)
works
Employees Department
ER MODEL IN DBMS
Extended ER features
Why do we need?
Extended ER features
Specialization Generalization
Aggregation
ER MODEL IN DBMS
Extended ER features
Specialization
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.
Inheritance
Attribute Participation
ER MODEL IN DBMS
Extended ER features
Aggregation
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
Instagram is a social media platform that allows users to share photos and
videos.
ER MODEL IN DBMS
ER Model of Instagram
ER Model of Instagram
Entities
userLikes
userProfile
userFriends
userPost
userLogin
ER MODEL IN DBMS
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
ER Model of Instagram
Step-2 : Specify entity characteristics/attributes
Attributes
ER Model of Instagram
Step-2 : Discover connections/relationships(also contraints like
mapping/participation)
ER Model of Instagram
Step-2 : Discover connections/relationships(also contraints like
mapping/participation)
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:
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.
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)