1.3 Data Models - Abhishek
1.3 Data Models - Abhishek
[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 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 !!)
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
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
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
ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Doctor Hospital
+Name +Name
+Speciality association +List of Doctors
ABHISHEK KUMAR SINGH | DEPARTMENT OF MATHEMATICS & COMPUTING| IIT (ISM) DHANBAD
Doctor Hospital
+Name +Name
+Speciality association +List of Doctors
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
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”
[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”
[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]
[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]
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]
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”
[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]
[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]
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