Practical 1,23 Full
Practical 1,23 Full
Sr
No, Name of Experiment Date Signature
Example- The college Database organizes the data about the admin, staff, students and faculty etc.
Using the database, you can easily retrieve, insert, and delete the information.
• Data Definition: It is used for creation, modification, and removal of definition that defines
the organization of data in the database.
• Data Updation: It is used for the insertion, modification, and deletion of the actual data in
the database.
• Data Retrieval: It is used to retrieve the data from the database which can be used by
applications for various purposes.
• User Administration: It is used for registering and monitoring users, maintain data integrity,
enforcing data security, dealing with concurrency control, monitoring performance and
recovering information corrupted by unexpected failure.
i)MySQL
MySQL is a free, open source relational database management system (RDBMS). It was initially
owned by MySQL AB, before being acquired by Sun Microsystems (part of Oracle Corporation
since 2010). MySQL was originally developed by Ulf Michael Widenius, Swedes David Axmark
and Allan Larsson, founders of MySQL AB.
The database is particularly renowned for its ease of use, quick performance, and ability to handle
large-scale web applications. It supports multiple storage engines, provides comprehensive data
security features, and offers robust replication capabilities. MySQL's versatility makes it a
preferred choice for developers and businesses ranging from small startups to large enterprises,
including major tech companies like Facebook, Twitter, and YouTube.
• Developer: Oracle Corporation
• Latest MySQL long-term release: 8.0
• Latest MySQL release: 8.0.36
• MySQL license: Dual-license (GPL and proprietary)
MongoDB is a powerful, open-source NoSQL database designed for modern, flexible data
management. It stores information in document-oriented, JSON-like formats, allowing dynamic
schema design that enables developers to handle complex, evolving data structures with exceptional
ease. The database system provides remarkable scalability, high performance, and robust features that
make it ideal for large-scale web applications and real-time analytics.
• Developer: MongoDB, Inc.
• Latest MongoDB long-term release: 7.0
• Latest MongoDB release: 7.0
• MongoDB license: Server Side Public License (SSPL)
(v) PostgreSQL
1.Data Organization and Storage: DBMS provides a structured approach to storing and organizing
data, creating logical frameworks that enable systematic information management. It establishes
relationships between different data elements, ensuring coherent and meaningful data representation.
2. Data Security Management: Implementing robust security protocols, DBMS controls user
access, authenticates credentials, and protects sensitive information from unauthorized modifications.
It establishes permission hierarchies and monitors data interactions to maintain confidentiality and
integrity.
4. Data Integrity Maintenance :DBMS ensures data accuracy through validation rules, constraint
enforcement, and consistent data management. It prevents inconsistent or duplicate entries,
maintaining high-quality information standards across organizational databases.
pg. 4 DBMS Practical File Jagriti Sharma
5. Scalability and Flexibility : Modern DBMS solutions offer adaptable architectures that can scale
horizontally and vertically, accommodating evolving business requirements. They support multiple
data types and provide flexible deployment options across different computing environments.
2. Data Security and Privacy: DBMSs provide a robust security framework that ensures the
confidentiality, integrity, and availability of data. They offer authentication and authorization features
that control access to the database. DBMSs also provide encryption capabilities to protect sensitive
data from unauthorized access.
3. Data Integrity and Consistency: Data integrity and consistency are crucial for any database.
DBMSs provide mechanisms that ensure the accuracy and consistency of data. These mechanisms
include constraints, triggers, and stored procedures that enforce data integrity rules. DBMSs also
provide features like transactions that ensure that data changes are atomic, consistent, isolated, and
durable (ACID).
4. Concurrent Data Access: A DBMS provides a concurrent access mechanism that allows multiple
users to access the same data simultaneously. This is especially important for organizations that
require real-time data access. DBMSs use locking mechanisms to ensure that multiple users can
access the same data without causing conflicts or data corruption.
5. Data Analysis and Reporting: DBMSs provide tools that enable data analysis and reporting.
These tools allow organizations to extract useful insights from their data, enabling better decision-
making. DBMSs support various data analysis techniques such as OLAP, data mining, and machine
pg. 5 DBMS Practical File Jagriti Sharma
learning. Moreover, DBMSs provide features like data visualization and reporting, which enable
organizations to present their data in a visually appealing and understandable way.
6. Scalability and Flexibility: DBMSs provide scalability and flexibility, enabling organizations to
handle increasing amounts of data. DBMSs can be scaled horizontally by adding more servers or
vertically by increasing the capacity of existing servers. This makes it easier for organizations to
handle large amounts of data without compromising performance.
Introduction to SQL
SQL stands for Structured Query Language. It is a standardized programming language used to
manage and manipulate relational databases. It enables users to perform a variety of tasks such as
querying data, creating and modifying database structures, and managing access permissions. SQL is
widely used across various relational database management systems such as MySQL, PostgreSQL,
Oracle, and SQL Server.
SQL Commands
SQL commands are essential for managing databases effectively. These commands are divided into
categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data
Control Language (DCL), Data Query Language h (DQL), and Transaction Control Language (TCL).
1. DDL: Data Definition Language in SQL
DDL or Data Definition Language actually consists of the SQL commands that can be used to
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
Command Description Syntax
CREATE Create database or its objects CREATE TABLE table_name (
column1 data_type,
column2 data_type );
ALTER Alter the structure of the database ALTER TABLE table_name ADD
COLUMN column_name data_type;
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.
Command Description
h Syntax
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. We can
explore more about transactions
9. ORDER BY: Used to sort the result set in ascending or descending order.
10. JOIN: Used to combine rows from two or more tables based on a related column between
them.
Conclusion
SQL commands such as DDL, DML, DCL, DQL, and TCL are foundational for effective database
management. From creating and modifying tables with DDL commands to managing transactions
with TCL commands in SQL, understanding each type of command enhances our database skills.
Whether we are manipulating data, or managing data, SQL provides all sets of tools.
SQL Queries
1.Creating a Database
Before working with tables, it is essential to create a database where all the data will be stored.
The CREATE DATABASE statement is used for this purpose, followed by the USE statement to
specify which database should be used for subsequent operations.
SQL Query:
CREATE DATABASE CompanyDB;
USE CompanyDB;
2. Creating a Table
Once the database is created, the next step is to create a table to store data. The CREATE TABLE
statement is used to define the table structure,
h including column names, data types, and constraints
such as primary keys.
Syntax - CREATE TABLE table_name (
column1 data_type constraints,
column2 data_type constraints’
...
);
SQL Query:
In this table, EmpID serves as the primary key to uniquely identify each employee. The Name and
Department columns store text values, Salary is a decimal number with two decimal places, and
JoinDate records the date of joining
After creating the table, data needs to be added. The INSERT INTO statement allows us to add
records to the table.
SQL Query: INSERT INTO Employees (EmpID, Name, Department, Salary, JoinDate)
VALUES
(101, 'Alice Johnson', 'IT', 75000.00, '2022-03-15'),
(102, 'Bob Smith', 'HR', 68000.00, '2021-07-10'),
(103, 'Charlie Davis', 'Finance', 80000.00, '2020-11-25'),
(104, 'David Wilson', 'IT', 72000.00, '2023-01-05'),
(105, 'Emma Brown', 'Marketing', 65000.00, '2019-09-30');
(102, '1984', 'George Orwell', 650.50),
The SELECT statement is used to fetch data from the table. If we want to retrieve all records from
the Employees table, we use the following query:
SQL Query: SELECT * FROM Employees;
This query returns all columns and rows from the table, allowing us to view the complete dataset.
AIM- The aim of this practical is to understand the different SQL commands used to modify and
man-age tables and data. This includes dropping a table, deleting records, altering the structure of a
table, and updating existing records.
1. DROP Statement - The DROP statement is used to permanently delete a table along with all
its data and structure. Once a table is dropped, it cannot be recovered unless it was backed up.
Syntax: DROP TABLE table_name;
Example- DROP TABLE Employees;
This command will completely remove the Employees table from the database.
2. DELETE Statement
The DELETE statement is used to remove specific records from a table while keeping the table structure
intact. If no condition is specified, all records will be deleted but the table will remain.
Syntax: DELETE FROM table_name WHERE condition;
DELETE FROM Employees WHERE Department = 'HR';
After SELECT * FROM Employees;
Output:
h
4. UPDATE Statement
The UPDATE statement is used to modify existing records in a table based on a condition. If no condition
is given, all records will be updated.
Syntax: UPDATE table_name SET column1 = value1,
column2 =value2 WHERE condition;
Aim: Basic SELECT Statement; selecting - all columns, specific columns; using arithmetic operators;
operator precedence; using parenthesis; defining a NULL Value; using column aliases; concatenation
operator; eliminating duplicate rows; displaying table structure.
A) SELECT STATEMENT:
The SELECT statement is one of the most fundamental SQL commands, used to retrieve data from one or
more tables in a database. It allows users to fetch specific columns, apply conditions, and filter results as
required. This statement is widely used in database queries to extract meaningful information.
Syntax - SELECT column1, column2, ... FROM table_name;
column1, column2, ... → Specifies the columns to retrieve.
table_name → Specifies the table from which data is fetched.
* → Used to select all columns from the table
Figure 7:This query retrieves all columns from the "Employees" table.
Figure 8:query retrieves only the "Name," "Department," and "Salary" columns
B) ARITHMATIC OPERATORS :
Arithmetic operators in SQL are used to perform mathematical operations on numerical values stored in a
database. These operators allow users to manipulate data within queries and retrieve meaningful results. SQL
supports basic arithmetic operations such as addition, subtraction, multiplication, division, and modulus.
Types of Arithmetic Operator
Addition (+): The addition operator is used to sum two numeric values.
Subtraction (-): The subtraction operator calculates the difference between two numeric values.
Multiplication (*): The multiplication operator multiplies two numeric values.
Division (/): The division operator divides one numeric value by another.
Modulus (%): The modulus operator returns the remainder after division.
h
These operators can be used in SELECT statements to perform calculations on table columns or with constant
values.
Operator Precedence in SQL
Operator precedence in SQL determines the order in which arithmetic operations are executed in an
expression. SQL follows standard mathematical rules:
Multiplication (*), Division (/), and Modulus (%) are evaluated first.
Addition (+) and Subtraction (-) are evaluated after multiplication, division, and modulus.
Parentheses () override the default precedence to ensure specific operations are executed first.
Figure 10:This query retrieves the employee’s name, salary, bonus, and calculates their total earnings using the addition operator.
Aliases are particularly useful when using calculations in the SELECT statement:
Example- SELECT Name, Salary * 12 AS Annual_Income FROM Employees;
This renames the calculated column as "Annual_Income", making the output more meaningful.
D) CONCATENATION OPERATOR h
The concatenation operator in SQL is used to merge two or more text values (strings) into a single result.
This is particularly useful when displaying full names, creating formatted outputs, or merging different
column values into a single column.
Different database systems use different operators for string concatenation:
MySQL & PostgreSQL: Use the CONCAT() function.
SQL Server: Uses the + operator. Oracle: Uses the || operator.
When we concatenate columns, we often add spaces or special characters between values to make the output
more readable. For example, combining a person’s first name and last name with a space in between.
Syntax – (MySQL & PostgreSQL)
SELECT
AIM- The objective of this practical is to learn how to filter and sort data in SQL using various conditions.
It covers selection criteria for restricting rows, comparison operators (BETWEEN, IN, LIKE, NULL), logical
conditions (AND, OR, NOT), and sorting data in ascending or descending order using the ORDER BY clause
Initial Table:
The BETWEEN operator is used to filter the records where a column’s value falls within a specified range.
It is inclusive, meaning it includes both the start hand end values. This operator is commonly used with
numerical values, dates, and even text.
Syntax: SELECT column_name(s)
FROM table_name WHERE column_name BETWEEN value1 AND value2;
Example- retrieve students whose ages are between 20 and 23 from the Students table.
SELECT * FROM Stud ents WHERE Age BETWEEN 20 AND 23;
Figure 12:Displaying Students whose age fall within the range using the BETWEEN operator in SQL.
We can also apply BETWEEN to date values. For example, to fetch students who joined between 2021-01-
01 and 2023-01-01
Here, the query retrieves students whose branch is either "Computer Science" or "Electronics" using
IN, instead of writing multiple OR conditions like :-
WHERE Branch = 'Computer Science' OR Branch = h 'Electronics';
We can also use IN with numerical values. For example, to select students with StudentIDs 101, 104, and 10.
It can be combined with AND, OR, and NOT for more refined filtering. AND with IN ensures all conditions
must be met, OR with IN selects records that match any condition, and NOT IN excludes specified values
Example: SELECT * FROM Students WHERE Branch IN ('IT', 'CS') AND City = 'Delhi';
Figure 14
[C] AND Operator - The AND operator is used when multiple conditions must be met for a record to be
selected. It returns only the rows where all the conditions specified in the WHERE clause are TRUE.
Syntax- SELECT column_name(s) Example- SELECT * FROM Students
FROM table name WHERE Branch = 'Electronics' AND City ='Bengaluru';
WHERE condition1 AND condition2;
[E] NOT Operator - The NOT operator is used to negate a condition in SQL. It returns rows where the
specified condition is false. This operator is often used with other conditions like BETWEEN, IN, LIKE, etc.,
to filter out specific values..
Syntax - SELECT column_name(s)
FROM table_name
WHERE NOT condition;
Example- all students who are NOT from the 'Electrical'
h branch from the Students table.
SELECT * FROM Students WHERE NOT Branch = 'Electrical';
Figure 16:Excluding students from the Electrical branch using the NOT operator
[F] LIKE operator- The LIKE operator is used in SQL to search for a specified pattern in a column. It
is commonly used with wildcards (% and _) to filter results based on partial matches.
Wildcards in LIKE:
% (percent): Represents zero, one, or multiple characters.
_ (underscore): Represents a single character at a specific position.
Syntax - SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
Using _ Wildcard, Retrieving all students whose names have 'a' as the second letter.
SELECT * FROM Students WHERE Name LIKE '_a%' ;
[G] ORDER BY Operator- The ORDER BY clause is used to sort the result set in ascending (ASC)
or descending (DESC) order based on one or more columns. By default, sorting is in ascending order if ASC
or DESC is not specified.
Syntax - SELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC | DESC];
Example: Sorting by Age in Ascending Order
Retrieving all student records sorted by age in ascending order :
SELECT * FROM Students ORDER BY Age ASC;
Figure 19:Sorting the student records by Age in ascending order using the ORDER BY clause