0% found this document useful (0 votes)
33 views66 pages

DBMS

The course focuses on database management systems, covering both SQL-based relational databases and NoSQL databases. Students will learn to create, query, and manage data, understand data modeling principles, and work with NoSQL systems like MongoDB. The course includes modules on database applications, data modeling, SQL, NoSQL databases, and database design, with an emphasis on practical applications and real-world use cases.

Uploaded by

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

DBMS

The course focuses on database management systems, covering both SQL-based relational databases and NoSQL databases. Students will learn to create, query, and manage data, understand data modeling principles, and work with NoSQL systems like MongoDB. The course includes modules on database applications, data modeling, SQL, NoSQL databases, and database design, with an emphasis on practical applications and real-world use cases.

Uploaded by

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

Course Objectives (CO)

The course study will help students to:

• This course aims to introduce the concepts of database management systems, focusing on
SQL-based relational databases and NoSQL databases.

Learning Outcomes (LO)

At the end of the course, students would be able to:


• Understand the principles of database systems and data modeling.
• Create, query, and manage data in SQL-based databases.
• Understand the principles and use cases of NoSQL databases.
• Work with a NoSQL database system.
Detailed course outline
Module 1
Introduction to Database System and Data Modelling
• Database-System Applications
• Purpose of Database Systems
• View of Data
• Database Languages
• Relational Databases
• Database Design
• Structure of Relational Databases
• Database Schema
• Keys
• Schema Diagrams
• Relational Query Languages
• Relational Operation
Module 2
Data Modeling: Entity-Relationship model
• Overview of the Design Process
• The Entity-Relationship Model
• Constraints
• Entity-Relationship Diagrams
• Entity-Relationship Design Issues
• Normalization
Module 3 Introduction to SQL
• Overview of the SQL Query Language
• SQL Data Definition
• Basic Structure of SQL Queries
• Set Operations
• Aggregate Functions
• Nested Subqueries
• Join Expressions
• Views
• Transactions • Authorization • Stored Procedures
Module 4
Introduction to NoSQL Databases
• The Value of Relational Databases
• Impedance Mismatch
• Application and Integration Databases
• Attack of the Clusters
• The Emergence of NoSQL
• Aggregate Data Models: Aggregates
• Column-Family Stores
• Types of NoSQL Databases (Document, Key-Value, Column, Graph)
• Use cases for NoSQL databases.
Module 5
Working with NoSQL databases
• Introduction to MongoDB
• Creating data in the NoSQL database
• Managing data in the NoSQL database
• CRUD operations in MongoDB

Textbook:
• Raghu Ramakrishnan and Johannes Gehrke, Database Management Systems, McGraw-
Hill.
• Shamkant B. Navathe, RamezElmasri, Database Systems, Pearson Higher Education.
Reference book:
• Abraham Silberschatz, Henry F. Korth, S. Sudarshan, DATABASE SYSTEM
CONCEPTS, Sixth Edition,
McGraw Hill.
• Garcia-Molina, Ullman, Widom: Database System Implementation, Pearson
education.
• S. K. Singh: Database Systems, Concepts, Design and Applications, Pearson
Education.
• G.K. Gupta: Database Management Systems, McGraw Hill.
• Toledo and Cushman: Database Management Systems, (Schaum‘s Outlines)
Module 1
Introduction to Database System and Data Modelling
• Database-System Applications
• Purpose of Database Systems
• View of Data
• Database Languages
• Relational Databases
• Database Design
• Structure of Relational Databases
• Database Schema
• Keys
• Schema Diagrams
• Relational Query Languages
• Relational Operation
Module 1
Introduction to Database System and Data Modelling
Q.1 Explain the application and Uses of Database Management System (DBMS)
1. Railway Reservation System
The database is required to record ticket
bookings, train departures, and arrival
statuses. Also, if trains are late, people are
informed through database updates.
2. Library Management System

There are thousands of books in the library,


so keeping a record of all the books in a copy
or register is very difficult. So, DBMS
maintains all the information related to book
issuing dates, book name, author, and book
availability.
3. Banking
Banking is one of the main applications of databases.
We all know there will be a thousand transactions
through banks daily, and we do this without going to
the bank. This is all possible just because of DBMS,
which manages all the bank transactions.

4. Universities and Colleges


Nowadays, examinations are done online at
universities and colleges. So, universities and
colleges maintain DBMS to store Student
registration details, results, courses, and grade
information in the database—
for example, telecommunications. Without DBMS,
there would be no telecommunication company.
DBMS is most beneficial to these companies for
storing call details and monthly postpaid bills.
5. Social Media Sites
We can access social media platforms by filling
in the required details. Many users sign up daily
on social websites like Facebook, Pinterest, and
Instagram. DBMS stores and maintains all user
information.

6. Military
In military areas, the DBMS is playing a vital
role. The military keeps records of soldiers, and
it has so many files that should be kept secure
and safe. DBMS provides high security to
military information.
7. Online Shopping
Nowadays, we all do Online shopping without
wasting time, thanks to DBMS. Products are
added and sold only with the help of DBMS,
such as Purchase information, invoice bills, and
payment.
8. Human Resource Management
The management keeps records of each
employee’s salary, tax, and work through
DBMS.

9. Manufacturing
Manufacturing companies make and sell
products daily. A DBMS keeps records of all
those details.
10. Airline Reservation system
Like the railway reservation system, airlines
need DBMS to keep records of flight arrival,
departure, and delay status.
Q.2 What is the purpose of a Database Management System?
The Database Management System (DBMS) is a software system that allows the user
to define, create, and maintain the database and provide control access to the data.

It is a collection of programs used for managing data, and simultaneously, it supports


different types of users to create, manage, retrieve, update, and store information.
Purpose

The purpose of DBMS is to transform the following −

1. Data into information.

2. Information into knowledge.

3. Knowledge to the action.


Previously, the database applications were built directly on the file system.

Drawbacks in File System


There are so many drawbacks to using the file system. These are mentioned below −
1. Data redundancy and inconsistency: Different file formats and duplication of
information in different files.
2. Difficulty accessing data: We must write a new program to carry out a new task.
3. Data Isolation − Different files and formats.
4. Integrity problems.
5. Atomicity of updates − Failures leave the database in an inconsistent state. For example,
the fund transfer from one account to another may be incomplete.
6. Concurrent access by multiple users.
7. Security problems.
Advantages of DBMS

The main Advantages of DBMS are as follows −

 Data independence and efficient access to data.

 Application Development time reduces.

 Security and data integrity.

 Uniform data administration.

 Concurrent access and recovery from crashes.


Q.3 Comparison between DBMS and File management system
Types of DBMS (Database Management System)
DBMS is software that manages the data for efficient storage and fast retrieval of data from
the database. MySQL, IBM Db2, Oracle, SQL, etc. are all DBMS software that manage the
data

Types of DBMS

There are four types of DBMS


1. Relational Database Management System (RDBMS)
2. Object-Oriented Database Management System.
3. Hierarchical Database management system.
4. Network Database management system.
1. Relational Database Management System
In RDBMS, data is stored in tables in the form of rows and columns, where a row represents
a record and a column represents the record's attributes.

For example, a student table stores the records of various students. A row of this table
represents the record of a single student, and the column represents the attributes of the
record, such as student ID, name, age, address, etc.

We use SQL to manage, organize, and


perform various operations on RDBMS.

Examples of RDBMS: MySQL, Oracle,


DB2 etc.
2. Object-Oriented Database Management System

Data is stored as objects, attributes, and methods. It typically stores and manages objects
directly on the database server’s disk. There are no tables, rows, columns, or foreign keys—
only objects.
For example: A house is an object. An object
has two characteristics: states and behavior.

In this example of a “House” being an object, the


state of “House” is its address, color, area, etc.,
and behavior is “Open main door,” “close main
door,” etc.

An object-oriented database can be represented


by the following diagram
3. Hierarchical Database Management
System
In a hierarchical database management system,
data is stored in the form of one-to-many
relationships. You can visualize it like a tree with
a root node attached to several descendant nodes Hierarchical Database
Management System
called leaves.
Examples of Hierarchical database systems are
IMS by IDM and Windows registry by
Microsoft.

For example, to store an organization’s data, the


root node is the organization itself. The immediate
child nodes are Employees, Managers, and
Directors. These child nodes can have further
child nodes, such as employees, who can have
child nodes such as engineers, housekeeping staff,
system admin, etc.
4. Network Database Management System

A network database management system (Network DBMS) is based on a network data


model, which allows each record to be related to multiple primary and secondary records.

A network database is based on a traditional hierarchical database, except it allows


each object to have multiple parents instead of a single parent. This means data in a
network database can have one-to-one or one-to-many relationships.
Types of DBMS Architecture
There are three types of DBMS architecture:

1. Single-tier architecture
2. Two-tier architecture
3. Three-tier architecture
1. Single tier architecture
In this type of architecture, the database is readily available on the client machine; any
request the client makes doesn’t require a network connection to act on the database.

For example, let's say you want to fetch an employee's records from the database. The
database is available on your computer system, so your computer will request the details and
records from the database as well. This type of system is generally referred to as a local
database system.
2. Two-tier architecture
In a two-tier architecture, the Database
system is on the server machine, and the
DBMS application is on the client machine.
These two machines are connected through Two-tier architecture
a reliable network, as shown in the diagram.

Whenever a client machine requests to


access the database present at the server
using a query language like SQL, the server
performs the request on the database and
returns the result to the client. Application
connection interfaces such as JDBC and
ODBC are used for the interaction between
server and client.
3. Three-tier architecture
In a three-tier architecture, another
layer is present between the client and
server machines. In this architecture,
Three-tier architecture
the client application doesn’t
communicate directly with the
database systems present at the server
machine; rather, the client application
communicates with the server
application, and the server application
internally communicates with the
database system present at the server.
DBMS – Three Level Architecture

This architecture has three


levels:
1. External level
2. Conceptual level
3. Internal level

DBMS – Three Level Architecture


1. External level
It is also called the view level. This level is called “view” because several users can view
their desired data from it, which is internally fetched from the database with the help of
conceptual and internal level mapping.

The user doesn’t need to know the database schema details, such as data structure, table
definition, etc. The user is only concerned about data, which returns to the view level after it
has been fetched from the database (present at the internal level).

The external level is the “top-level” of the Three Level DBMS Architecture.
2. Conceptual level
It is also called the logical level. This level describes the whole design of the database, such
as the relationships among data, the schema of data, etc.

This level of architecture also implements database constraints and security. The DBA
(database administrator) maintains this level.

3. Internal level

This level is also known as the physical level. It describes how the data is actually stored
in the storage devices and is responsible for allocating space to the data. This is the
lowest level of the architecture.
View of data in DBMS
Abstraction is one of the main features of database systems. Hiding irrelevant
details from users and providing abstract views of data to users helps in easy and
efficient user-database interaction. In DBMS architecture, the top level of that
architecture is the “view level.” The view level provides the “view of data” to the
users and hides irrelevant details, such as data relationship, database schema,
constraints, security, etc, from the user.
What is Database design?
Database Design can be defined as a set of procedures or collection of tasks involving
various steps taken to implement a database. A good database design is important. It helps
you get the correct information when you need it. Following are some critical points to keep
in mind to achieve a good database design:

Following are some critical points to keep in mind to achieve a good database
design:
 Data consistency and integrity must be maintained.
 Low Redundancy
 Faster searching through indices
 Security measures should be taken by enforcing various integrity constraints.
 Data should be stored in fragmented information in the most atomic format
possible.
What are the Following Steps that a Database Designer can take to Ensure
Good Database Design?

Step 1: Determine the goal of your database and ensure clear communication with the
stakeholders (if any). Understanding the purpose of a database will help you consider various
use cases, where problems may arise, and how you can prevent them.

Step 2: List all the entities that will be present in the database and what relationships exist
among them.

Step 3: Organize the information into different tables so there is little or no redundancy.

Step 4: Ensure uniqueness in every table. The uniqueness of records present in any relation is a
crucial part of database design that helps us avoid redundancy. Identify the key attributes to
uniquely identify every row from columns. You can use various key constraints to ensure the
uniqueness of your table. Also, keep in mind that the uniquely identifying records must
consume as little space as possible and shall not contain any NULL values.
Step 5: After all the tables are structured and information is organized, normalization forms
are applied to identify anomalies that may arise and redundancies that can cause
inconsistency in the database.
Primary Terminologies Used in Database Design
Following are the terminologies that a person should be familiar with before designing a
database:
1. Redundancy:
Redundancy refers to data duplication. There can be specific use cases when we need or don't
need redundancy in our Database. For example, if we have a banking system application, we
may need to prevent redundancy in our Database strictly.
2. Schema:
A schema is a logical container that defines the structure and manages the organization of the
stored data. It consists of rows and columns, with data types for each column.
3. Records/Tuples:
A Record or a tuple is the same. It’s where our data is stored inside a table
4. Indexing:
Indexing is a data structure technique that promotes efficient retrieval of the data stored in our
database.
5. Data Integrity & Consistency:
Data integrity refers to the quality of the information stored in our database, and consistency
refers to the correctness of the data stored.
6. Data Models:
Data models provide us with visual modeling techniques to visualize the data and the
relationships among those data. Examples include a network Model, an object-oriented
model, a Hierarchical model, etc.
7. Normalization:
Organizes data to reduce redundancy and dependency by dividing larger tables into smaller
ones and defining relationships. It ensures data storage and consistency.
8. Functional Dependency:
Functional Dependency is a relationship between two attributes of the table that represents that
another can determine the value of one attribute. Ex: {A -> B}, A & B are two attributes, and
attribute A can uniquely determine the value of B.
9. Transaction:
Transaction is a single logical unit of work. It signifies that some changes have been made to
the database. A transaction must satisfy the ACID or BASE properties (depending on the type
of Database).

10. Schedule:
The schedule defines the sequence of transactions in which they're executed by one or
multiple users.
11. Concurrency:
Concurrency refers to allowing multiple transactions to operate simultaneously without
interfering with one another.
12. Constraints:
Constraints are the rules applied to fields in a table to enforce data integrity, such as NOT
NULL, UNIQUE, CHECK, etc. They ensure data quality and accuracy.
Database Design Lifecycle
The database design lifecycle goes something like this:
1. Requirement Analysis
It's crucial to understand the requirements of our application so that you can think productively
and imply appropriate integrity constraints to maintain data integrity and consistency.

2. Logical & Physical Design


This is the actual design phase that involves various steps to be taken while designing a
database. This phase is further divided into two stages:
•Logical Data Model Design: This phase consists of coming up with a high-level design of our
database based on initially gathered requirements to structure & organize our data accordingly.
A high-level overview on paper is made of the database without considering the physical level
design, this phase proceeds by identifying the kind of data to be stored and what relationship
will exist among those data.
The core functionality of this phase is identifying entities, key attributes, and the constraints to
be implemented. It involves techniques such as Data Modeling to visualize data, normalization
to prevent redundancy, etc.
An Example of Logical Design
Physical Design
The main purpose of the physical design is to actually implement the logical design, that is, to
show the structure of the database along with all the columns and their data types, rows,
relations, and relationships among data and clearly define how relations are related to each
other.
In conclusion, a good database design is
essential to a strong database management
system (DBMS). It provides the basis for
data governance, storage, and retrieval. The
quality of a database has a direct impact on
a system’s overall performance and
dependability. When designing a database
to meet the needs of your organization and
your users, it is important to consider data
organization, standardization, performance,
integrity, and more.
What is the Relational Model?
The relational model represents how data is stored in Relational Databases. A relational
database consists of a collection of tables, each assigned a unique name.
Consider a relation STUDENT with attributes ROLL_NO, NAME, ADDRESS, PHONE, and
AGE shown in the table.
Table STUDENT
Important Terminologies in Relational Databases
1. Attribute: Attributes are the properties that define an entity. e.g. ROLL_NO, NAME,
ADDRESS.
2. Relation Schema: A relation schema defines the relation's structure and represents the
relation's name with its attributes. For example, the relation schema for STUDENT
(ROLL_NO, NAME, ADDRESS, PHONE, and AGE) is the relation schema for
STUDENT. If a schema has more than one relation, it is called a Relational Schema.
3. Tuple: Each row in the relation is known as a tuple. The above relation contains four
tuples, one of which is shown as:
4. Relation Instance: A relation instance is the set of tuples of a relation at a particular
time. It can change whenever there is an insertion, deletion, or update in the database.
5. Degree: The number of attributes in the relation is known as the degree of the relation.
The STUDENT relation defined above has degree 5.
6. Cardinality: The number of tuples in a relation is called cardinality. The STUDENT
relation defined above has cardinality 4.
7. Column: The column represents the set of values for a particular attribute. The column
ROLL_NO is extracted from the relation STUDENT.
8. NULL Values: A value that is not known or unavailable is called a NULL value. It is
represented by NULL. For example, the phone number of a student with ROLL_NO 4 is
NULL.
9. Relation Key: These are the keys used to identify the rows uniquely or also help identify
tables. These are of the following types:
PRIMARY KEY in SQL
 A primary key in SQL is a column (or group of columns) that uniquely identifies the
records in a table.
 It must contain unique values and can not have NULL values.
 A table can only have one primary key, but that primary key can consist of one or more
columns.
 When there are two or more columns in the primary key, it is called a composite key.
 A primary key automatically has a defined UNIQUE constraint, and it ensures that there
are no duplicate or NULL values in that column.
Create PRIMARY KEY in SQL Example

CREATE TABLE Persons (


PersonID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
Important Points About SQL PRIMARY KEY

1. A primary key is a column or a set of columns in a table that uniquely identifies


each row.
2. It ensures data integrity by preventing duplicate records and null values.
3. A primary key can be defined as a single column (simple primary key) or multiple
columns (composite primary key).
4. A primary key automatically creates a unique index on the key column(s),
improving query performance.
5. Establishing relationships between tables using SQL primary key and foreign key
improves database design, reduces data redundancy, and improves data
consistency.
Benefits of Using Primary Keys
1. Data Integrity: The primary key enforces data integrity by ensuring each
record is unique.
2. Efficient Querying: Since a primary key automatically creates an index,
querying for records by the primary key is faster.
3. Referential Integrity: Primary keys establish relationships between tables
(via foreign keys), ensuring consistency across related data.
Common Issues and Best Practices
1. Avoid NULL values: Always ensure that the columns involved in the primary key do
not accept NULL values.
2. Choose meaningful primary keys: Choose a primary key that naturally fits the data
and serves as a meaningful identifier, like an ID field.
3. Composite Keys: Be cautious when using composite keys. While they are helpful in
some scenarios, they can make queries more complex. Use a simple key or generate
an artificial primary key (like an ID) if possible.
4. Changing Primary Keys: Once a primary key is established, changing it can be
difficult because of the interdependencies with other tables (foreign key constraints).
Always plan when designing your database schema.
What is Candidate Key?
A candidate key is a set of attribute(s) uniquely identifying the tuples in relation or table.
As we know, the Primary key is a minimal super key, so there is one and only one primary
key in any relationship, but there is more than one candidate key that can take place. The
candidate key’s attributes can contain a NULL value that opposes the primary key. For
example,
Student{ID, Aadhar_ID, F_name, M_name, L_name, Age}
Here, we can see the candidate keys and Aadhar IDs. More than one candidate key can
uniquely identify a tuple in a relation or become the primary key.
Advantages of Candidate Key
•Flexibility: There are chances of having multiple candidate in a table which provides
flexibility in choosing the one primary key that suits the best for the table among all
candidate key.
•Uniqueness: It ensures that even if the primary key is not suitable still the records can be
identified uniquely.
•Backup for primary key: If there is any need or primary key is not available, then
candidate keys can be used as a backups for the primary key.

Disadvantages of Candidate Key


•More Complex: Having multiple candidate key can make the table complex to manage
and understanding the database schema as well.
•Extra Space: If multiple candidate keys are indexed, then they can add an extra storage
and indexing overhead.
What is Super Key?
Super Key is an attribute (or set of attributes) that is used to uniquely identify all
attributes in a relation. All super keys can’t be candidate keys but the reverse is true. In
relation, several super keys are more than several candidate keys.

For example: In the above EMPLOYEE table,


for(EMPLOEE_ID, EMPLOYEE_NAME), the
name of two employees can be the same, but
their EMPLYEE_ID can't be the same. Hence,
this combination can also be a key.

The super key would be EMPLOYEE-ID


(EMPLOYEE_ID, EMPLOYEE-NAME), etc.
Foreign key
Foreign keys are the columns of the table used to point to the primary key of another
table.
Every employee works in a specific department, and the employee and department are
different entities. So we can't store the department's information on the employee table.
That's why we link these two tables through the primary key of one table.
We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in
the EMPLOYEE table.
Department_Id is the foreign key in the EMPLOYEE table, and both tables are related.
5. Alternate key
One or more attributes or a combination of attributes may uniquely identify each tuple in a
relation. These attributes or combinations of the attributes are called the candidate keys. One
key is chosen as the primary key from these candidate keys, and the remaining candidate key,
if it exists, is termed the alternate key.
In other words, the total number of the alternate keys is the total number of candidate keys
minus the primary key. The alternate key may or may not exist. If only one candidate key
exists in a relation, it has no alternate key.
For example, employee relation has two attributes, Employee_Id and PAN_No, that act as
candidate keys. Employee_Id is chosen as the primary key in this relation, so the other
candidate key, PAN_No, acts as the Alternate key.
6. Composite key
Whenever a primary key consists of more than one attribute, it is known as a composite
key, which is also known as a Concatenated Key.
7. Artificial key
Artificial keys are keys created using arbitrarily assigned data. They are created when
a primary key is large and complex and has no relationship with many other relations.
The data values of artificial keys are usually numbered in serial order.

For example, the primary key, composed of


Emp_ID, Emp_role, and Proj_ID, is large
in employee relations. So , it would be
better to add a new virtual attribute to
uniquely identify each tuple in the relation.
Database schema
A schema is a blueprint or structure that defines how data is organized and stored in a
database. It outlines the database's tables, fields, relationships, views, indexes, and other
elements. The schema defines the logical view of the entire database and specifies the rules
that govern the data, including its types, constraints, and relationships .
Database Schema
A database schema is the design or structure of a database that defines how data is organized and
how different data elements relate to each other. It acts as a blueprint, outlining tables, fields,
relationships, and rules that govern the data.

Key points about a database schema:


•It defines how data is logically organized, including tables, fields, and relationships.
•It outlines the relationships between entities, such as primary and foreign keys.
•It helps resolve issues with unstructured data by organizing it clearly and in a structured way.
•Database schemas guide how data is accessed, modified, and maintained.
In simple terms, the schema provides the framework for understanding, managing, and
using data in a database. Database designers create it to ensure consistency and efficient
organization of data.
Types of Database Schemas

Physical Database Schema


A physical schema defines how data is stored in the storage system, including arranging
files, indices, and other storage structures. It specifies the actual code and syntax needed to
create the database structure. It determines where and how the data is stored in the physical
storage medium.
The database administrator decides the storage locations and data organization within the
storage blocks. This schema represents the lowest level of abstraction.
Logical Database Schema
•A logical database schema defines the logical structure of the data, including tables,
views, relationships, and integrity constraints. It describes how data is organized in
tables and how the attributes of these tables are connected. The logical schema ensures
that the data is stored in an organized manner while maintaining data integrity.
•Using Entity-Relationship (ER) modeling, the logical schema outlines the
relationships between different data components. It also defines integrity constraints to
ensure data quality during insertion and updates.
•This schema represents a higher abstraction level than the physical schema,
focusing on logical constraints and how the data is structured without dealing with the
physical storage details.
View Database Schema
The view schema is the highest level of abstraction in a database, focusing on how users
interact with the database. It defines the interface through which users can access and
manipulate data without understanding the underlying storage mechanisms.
A database can have multiple view schemas or subschemas, each providing a different data
perspective and describing only a part of the database.
Creating Database Schema
The statement “CREATE SCHEMA” is used in every database to create a schema. But
different databases have different meanings for this. Below, we’ll be looking at some
statements for creating a database schema in other database systems:
1. MySQL: In MySQL, we use the “CREATE SCHEMA” statement to create the database
because the CREATE SCHEMA and CREATE DATABASE statements are similar.
2. SQL Server: In SQL Server, we use the “CREATE SCHEMA” statement for creating a
new schema.

You might also like