Dbms Notes
Dbms Notes
A file system and a DBMS are two kinds of data management systems that
are used in different capacities and possess different characteristics. A File
System is a way of organizing files into groups and folders and then storing
them in a storage device. It provides the media that stores data as well as
enables users to perform procedures such as reading, writing, and even
erasure.
On the other hand, DBMS is a more elaborate software application that is
solely charged with the responsibility of managing large amounts of
structured data. It provides functionalities such as query, index, transaction,
as well as data integrity. Although the file system serves well for the purpose
of data storage for applications where data is to be stored simply and does
not require any great organization, DBMS is more appropriate for
applications where data needs to be stored and optimized for organizational
and structural needs, security, etc.
File System
The file system is basically a way of arranging the files in a storage medium
like a hard disk. The file system organizes the files and helps in the retrieval
of files when they are required. File systems consist of different files which
are grouped into directories. The directories further contain other folders
and files. The file system performs basic operations like management, file
naming, giving access rules, etc.
Example: NTFS(New Technology File System) , EXT(Extended File
System).
DBMS ( Database Management System)
Database Management System is basically software that manages the
collection of related data. It is used for storing data and retrieving the data
effectively when it is needed. It also provides proper security measures for
protecting the data from unauthorized access. In Database Management
System the data can be fetched by SQL queries and relational algebra. It
also provides mechanisms for data recovery and data backup.
Example:
Oracle, MySQL, MS SQL server.
Difference Between File System and DBMS
There is no efficient
Efficient query processing is
Query query processing in the
there in DBMS.
processing file system.
It has a comparatively
It is less expensive than
higher cost than a file
DBMS.
Cost system.
In DBMS data
independence exists, mainly
of two types:
There is no data
1) Logical Data
independence.
Independence .
Data 2)Physical Data
Independence Independence.
Data is distributed in
Due to centralized nature
many files. So, it is not
data sharing is easy
Sharing easy to share data.
On the client side, the user interfaces and application programs are run. The
application on the client side establishes a connection with the server side
to communicate with the DBMS. For Example: A Library Management
System used in schools or small organizations is a classic example of two-
tier architecture.
3-Tier Architecture
In 3-Tier Architecture, there is another layer between the client and the
server. The client does not directly communicate with the server. Instead, it
interacts with an application server which further communicates with the
database system and then the query processing and transaction management
takes place. This intermediate layer acts as a medium for the exchange of
partially processed data between the server and the client. This type of
architecture is used in the case of large web applications.
Example: E-commerce Store
User: You visit an online store, search for a product and add it to your
cart.
Processing: The system checks if the product is in stock, calculates
the total price and applies any discounts.
Database: The product details, your cart and order history are stored
in the database for future reference.
SQL Commands | DDL, DQL, DML, DCL and TCL Commands
SQL commands are the fundamental building blocks for communicating
with a database management system (DBMS). It is used to interact with the
database with some operations. It is also used to perform specific tasks,
functions, and queries of data. SQL can perform various tasks like creating
a table, adding data to tables, dropping the table, modifying the table, set
permission for users.
SQL Commands are mainly categorized into five categories:
DDL – Data Definition Language
DQL – Data Query Language
DML – Data Manipulation Language
DCL – Data Control Language
TCL - Transaction Control Language
1. DDL - Data Definition Language
DDL or Data Definition Language actually consists of the SQL commands
that can be used for defining, altering and deleting database structures such
as tables, indexes and schemas. It simply deals with descriptions of the
database schema and is used to create and modify the structure of database
objects in the database
Common DDL Commands
ALTER TABLE
Alter the structure of table_name ADD
ALTER
the database COLUMN column_name
data_type;
COMMENT
Add comments to the
COMMENT 'comment_text' ON
data dictionary
TABLE table_name;
Command Description Syntax
RENAME TABLE
Rename an object
RENAME old_table_name TO
existing in the database
new_table_name;
Example:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
hire_date DATE
);
In this example, a new table called employees is created with columns for
employee ID, first name, last name and hire date.
2. DQL - Data Query Language
DQL statements are used for performing queries on the data within schema
objects. The purpose of the DQL Command is to get some schema relation
based on the query passed to it. This command allows getting the data out
of the database to perform operations with it. When a SELECT is fired
against a table or tables the result is compiled into a further temporary table,
which is displayed or perhaps received by the program.
DQL Command
Indicates
SELECT column1
FROM the table(s) from
FROM table_name;
which to retrieve data.
Filters
SELECT column1
rows before any
WHERE FROM table_name
grouping or
WHERE condition;
aggregation
SELECT column1,
Groups rows that have
GROUP AGG_FUNCTION(column2)
the same values in
BY FROM table_name
specified columns.
GROUP BY column1;
SELECT column1,
AGG_FUNCTION(column2)
Filters the results
HAVING FROM table_name
of GROUP BY
GROUP BY column1
HAVING condition;
SELECT column1
ORDER Sorts the result set by FROM table_name
BY one or more columns ORDER BY column1 [ASC |
DESC];
Command Description Syntax
By default, it sorts
in ascending SELECT * FROM table_name
LIMIT
order unless specified LIMIT number;
as DESC
Example:
SELECT first_name, last_name, hire_date
FROM employees
WHERE department = 'Sales'
ORDER BY hire_date DESC;
This query retrieves employees' first and last names, along with their hire
dates, from the employees table, specifically for those in the 'Sales'
department, sorted by hire date.
3. DML - Data Manipulation Language
The SQL commands that deal with the manipulation of data present in the
database belong to DML or Data Manipulation Language and this includes
most of the SQL statements. It is the component of the SQL statement that
controls access to data and to the database. Basically, DCL statements are
grouped with DML statements.
Common DML Commands
Delete records
DELETE FROM table_name WHERE
DELETE from a database
condition;
table
Call a PL/SQL
CALL or JAVA CALL procedure_name(arguments);
subprogram
Describe the
EXPLAIN EXPLAIN PLAN FOR SELECT *
access path to
PLAN FROM table_name;
data
Example:
INSERT INTO employees (first_name, last_name, department)
VALUES ('Jane', 'Smith', 'HR');
This query inserts a new record into the employees table with the first name
'Jane', last name 'Smith' and department 'HR'.
4. DCL - Data Control Language
DCL (Data Control Language) includes commands such as GRANT and
REVOKE which mainly deal with the rights, permissions and other controls
of the database system. These commands are used to control access to data
in the database by granting or revoking permissions.
Common DCL Commands
Command Description Syntax
REVOKE [GRANT
Removes previously
OPTION FOR]
granted privileges from
privilege_type
a user account, taking
REVOKE [(column_list)] ON
away their access to
[object_type]
certain database
object_name FROM user
objects or actions.
[CASCADE];
Example of DCL
GRANT SELECT, UPDATE ON employees TO user_name;
This command grants the user user_name the permissions to select and
update records in the employees table.
5. TCL - Transaction Control Language
Transactions group a set of tasks into a single execution unit. Each
transaction begins with a specific task and ends when all the tasks in the
group are successfully completed. If any of the tasks fail, the transaction
fails. Therefore, a transaction has only two results: success or failure.
Common TCL Commands
Creates a savepoint
SAVEPOINT
SAVEPOINT within the current
savepoint_name;
transaction
Example:
BEGIN TRANSACTION;
UPDATE employees SET department = 'Marketing' WHERE department =
'Sales';
SAVEPOINT before_update;
UPDATE employees SET department = 'IT' WHERE department = 'HR';
ROLLBACK TO SAVEPOINT before_update;
COMMIT;
In this example, a transaction is started, changes are made, and a savepoint
is set. If needed, the transaction can be rolled back to the savepoint before
being committed.
SQL Aggregate functions
Last Updated : 02 Aug, 2025
Id Name Salary
1 A 802
2 B 403
3 C 604
4 D 705
5 E 606
Id Name Salary
6 F NULL
TotalEmployees
TotalSalary
3120
Output:
AverageSalary
624
802
Name TotalSalary
A 802
B 403
C 604
D 705
E 606
F -
Name TotalSalary
A 802
C 604
D 705
E 606