0% found this document useful (0 votes)
18 views28 pages

1.3 Data Models - Abhishek

The document discusses different data models for representing data in a database management system (DBMS), including the object-oriented data model, graph data model, and entity-relationship (ER) model. The ER model is commonly used to conceptually represent user data requirements before deciding on storage. An ER model has entities representing real-world nouns and relationships representing verbs between entities. ER models can be visually depicted using ER diagrams.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views28 pages

1.3 Data Models - Abhishek

The document discusses different data models for representing data in a database management system (DBMS), including the object-oriented data model, graph data model, and entity-relationship (ER) model. The ER model is commonly used to conceptually represent user data requirements before deciding on storage. An ER model has entities representing real-world nouns and relationships representing verbs between entities. ER models can be visually depicted using ER diagrams.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Database Management Systems

[MCC511]
Winter, 2023-24

Lecture 1.3
Data Models
ABHISHEK KUMAR SINGH
ASSOCIATEPROFESSOR
DEPARTMENT OF MATHEMATICS & COMPUTING
IIT(ISM) DHANBAD
Last time …
We discussed the idea of Abstraction with respect to the data in an application
We talked about three levels or abstractions of data
◦ Physical Level – information about the actual storage of data on a medium (e.g., bytes and collections of bytes)
◦ Logical Level – information about what this data represents and the inter-relationships within the data
◦ View Level – data as perceived by users of an application, much closer to the real world

We talked about Physical Data Independence


◦ It is the ability to make changes at the Logical level, without having to worry about the issues at Physical level
◦ A DBMS can provide this independence to you

We saw that the role that we are basically training you is that of a Database Administrator
◦ There are other types of users in the DBMS ecosystem as well (check out your homework today !!)

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
How to represent data?
Given that you have something or someone to take care of data at the Physical Level …
◦ … you are now required to handle the challenges at the Logical Level (and sometimes the View Level)

It means that you must design a way to represent this data logically …
◦ … so that you can harness the power of a DBMS (and avoid writing the File Handling code !!)

So what options do you have at your disposal?


◦ There are quite a few actually, but finding the best one is not easy

The most popular one is the duo comprising of Entity-Relationship (ER) Model and Relational Model
◦ We will spend a lot of time on this, so let us come back to it later

For now let us have a brief look at two other types of models which may be of interest to you today
◦ These models have generated a renewed interest ever since the “NoSQL” philosophy became popular

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Object Oriented Data Model
Remember your course on Object Oriented (OO) Programming?
◦ The way you represented data in your applications is an example of the Object Oriented Data Model

In OO Data Model, you attempt to capture the real world data in terms of Objects and their relationships
◦ If you wrote any C++ programs to read or write objects using File Handling libraries, that is what you did !!

The idea is to store the data and interrelationships in the form of objects
A DBMS that supports defining data with the OO model is called an Object Oriented DBMS (OODBMS)
◦ A popular example in this category is a DBMS for Mobile Phones called Realm by MongoDB

As there are not many OODBMSs around, a hybrid of OO Model with Relational Model is also popular
◦ This model is called the Object-Relational Data Model
◦ There are solutions available to map definitions in the OO Model to a DBMS that supports the Relational Model
◦ This process is called Object-Relational Mapping or ORM in short
◦ Example: Hibernate is a popular Java-based ORM solution

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Graph Data Model
For certain cases, expressing the data in the form of a graph seems quite natural
◦ Think about relationships with many-to-many mappings … expressing them as a graph seems sensible

Example: Capturing the relationships between Doctors and Hospitals


◦ A Doctor maybe working for multiple Hospitals
◦ A Hospital may have multiple doctors on their panel
◦ There may be redundancies – a Hospital could have more doctors than one for a particular speciality

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Doctor Y

can be replaced by

works at
Doctor X
works at
works at
Hospital C

Hospital A
works at

Doctor Z

works at

Hospital B

An example of Graph Data Model: Capturing the relationships between Doctors and Hospitals

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Doctor Y

can be replaced by

works at
Doctor X
works at
works at
Hospital C

Hospital A
works at

Doctor Z
You may imagine this scenario as an
works at object storing Pointers to other
objects which are “related” to it in
Hospital B some fashion

An example of Graph Data Model: Capturing the relationships between Doctors and Hospitals

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Graph Data Model
For certain cases, expressing the data in the form of a graph seems quite natural
◦ Think about relationships with many-to-many mappings … expressing them as a graph seems sensible

Example: Capturing the relationships between Doctors and Hospitals


◦ A Doctor maybe working for multiple Hospitals
◦ A Hospital may have multiple doctors on their panel
◦ There may be redundancies – a Hospital could have more doctors than one for a particular speciality

Such a representation of data can be termed as a Graph Data Model


◦ Pros
◦ Addition or Deletion of new data is easy and intuitive
◦ Different nodes of the graph may have different number of edges originating or culminating
◦ Cons
◦ In order to “reach” a node, it may be required to go through multiple nodes

DBMSs that support the Graph Models are colloquially called Graph Databases (e.g. Neo4j)
ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Entity Relationship Model
Building a software application involves interacting with the users to know their data requirements
Before deciding the storage details, these requirements are often represented conceptually
◦ The most common way to do so, is by using the Entity Relationship (ER) Model

Remember, the ER model is only a higher-level, conceptual model


◦ In order to use a DBMS, you will have to use a model supported by your DBMS

An ER Model has two elements


◦ Entities – the “nouns” in the real world, and
◦ Relationships – the “verbs” that bind the “nouns” together to make sense

A diagram that is used to pictorially represent an ER Model is called the ER Diagram

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Doctor Hospital
+Name +Name
+Speciality association +List of Doctors

An example of ER Diagram: Representing the relationships between Doctors and Hospitals

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Doctor Hospital
+Name +Name
+Speciality association +List of Doctors

An example of ER Diagram: Representing the relationships between Doctors and Hospitals

Simply put, in an ER Diagram we note down the properties


of our entities and show the relationships between them

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Entity Relationship Model
Building a software application involves interacting with the users to know their data requirements
Before deciding the storage details, these requirements are often represented conceptually
◦ The most common way to do so, is by using the Entity Relationship (ER) Model

Remember, the ER model is only a higher-level, conceptual model


◦ In order to use a DBMS, you will have to use a model supported by your DBMS

An ER Model has two elements


◦ Entities – the “nouns” in the real world, and
◦ Relationships – the “verbs” that bind the “nouns” together to make sense

A diagram that is used to pictorially represent an ER Model is called the ER Diagram


We will be looking at ER Diagrams at somewhat depth later, so let us move on !!

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Relational Data Model
The most common data model that has been used in software solutions is the Relational Model
◦ Introduced by Ted Codd in 1970, the Relational Model soon became the de-facto data model for DBMSs

The core idea behind a Relational model is to represent all the data in the forms of Tables

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Table Doctor
Name Hospital
X A
X B
X C
Y C
Z B

Table Hospital
Name Doctor
A X
B X
B Z
C X
C Y

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Table Doctor
Name Hospital
X A
X B
X C
Y C
Z B

Table Hospital
Name Doctor The idea is to keep enough
A X data (which may, as you see,
seem redundant as well) to
B X capture the real world
B Z scenarios
C X
C Y

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Relational Data Model
The most common data model that has been used in software solutions is the Relational Model
◦ Introduced by Ted Codd in 1970, the Relational Model soon became the de-facto data model for DBMSs

The core idea behind a Relational Model is to represent all the data in the forms of Tables
A DBMS that supports defining a Relational Model of data is called a Relational DBMS or RDBMS
These tables are “joined” with each other to represent real world relationships
◦ The ability to efficiently join together, data from multiple tables, is a crucial function of the RDBMS

Relational Model is built upon Mathematical foundations such as Set Theory and 1st Order Logic
◦ This makes it a perfect candidate for a DBMS to support

We will check out the Relational Model later in the course in detail

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …

[View Level]

If we go back to the
Abstraction Levels
[Logical Level]

[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

[Logical Level]

[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

Done by Domain Experts,


[View Level] Software Architects, Data
Architects etc.
“We have created an ER Diagram to represent the relationship
between the Doctors and the Hospitals”

[Logical Level]

[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

Done by Domain Experts,


[View Level] Software Architects, Data
Architects etc.
The ER Model, thus, is a tool to capture real “We have created an ER Diagram to represent the relationship
world relationships, before picking a DBMS between the Doctors and the Hospitals”

[Logical Level]

[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

“We have created an ER Diagram to represent the relationship


between the Doctors and the Hospitals”

“We have two Tables, called Hospital and Doctor respectively”


[Logical Level]

[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

“We have created an ER Diagram to represent the relationship


between the Doctors and the Hospitals”

“We have two Tables, called Hospital and Doctor respectively”


[Logical Level]
Performed by Software Architects,
Data Architects, Project Managers,
Team Leads etc., with (maybe) the
Database Administrator in the loop
[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

“We have created an ER Diagram to represent the relationship


between the Doctors and the Hospitals”

“We have two Tables, called Hospital and Doctor respectively”


[Logical Level]
Keep in mind that both ER Models
and Relational Models are
essentially at the Logical level, it is
just that the former is closer to the
[Physical Level] View level than the latter

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

Instead of using the Relational Model, you can “We have created an ER Diagram to represent the relationship
also use the OO Model or the Graph Model between the Doctors and the Hospitals”

“We have two Tables, called Hospital and Doctor respectively”


[Logical Level]

[Physical Level]

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

“We have created an ER Diagram to represent the relationship


between the Doctors and the Hospitals”

“We have two Tables, called Hospital and Doctor respectively”


[Logical Level]

[Physical Level] “The data must be stored efficiently for retrieval and updates”

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Summing it up …
“We need an application that stores which Doctor is available at
which Hospital, and vice-versa”

[View Level]

“We have created an ER Diagram to represent the relationship


between the Doctors and the Hospitals”

“We have two Tables, called Hospital and Doctor respectively”


[Logical Level]
Taken care by the DBMS, as
instructed by the Database
Administrator
[Physical Level] “The data must be stored efficiently for retrieval and updates”

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
In the next lecture …
Although the ER Model could, in theory, be used with other models as well …
◦ … in general, you will see a tight coupling between the ER Diagrams and Relational Data Design
◦ It could be because in many cases, there is a one-to-one mapping between the two …
◦ … i.e., for every Entity, you will probably see a corresponding Table

From here on, we will forget about the other models (since they are not a part of the syllabus )…
◦ … and concentrate upon the Relational Model, in conjugation with the ER Model

In the next two lectures, we will discuss RDBMSs through a bird's-eye view
◦ The idea is to brief you about the various tasks that an RDBMS performs for us !!

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Homework
There are many types of actors in a DBMS ecosystem
◦ Read about all of them and the roles that they play
◦ Section 1.12 from Korth et al. or Section 1.4 from Navathe et al. should be sufficient

For the example of Doctors and Hospitals, what do you think the OO Model should look like?
◦ Try to write some code to represent the example using a binary data file
◦ How easy or difficult is it to modify or retrieve the data that you stored in the file? Introspect.

ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD

You might also like