0% found this document useful (0 votes)
2 views19 pages

Practical 1,23 Full

The document provides an introduction to Database Management Systems (DBMS), detailing its role in data organization, security, integrity, and performance optimization. It discusses various DBMS software such as MySQL, Microsoft SQL Server, Oracle DBMS, MongoDB, and PostgreSQL, highlighting their features and licensing. Additionally, it covers SQL commands and their categories, including Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL), essential for managing databases.
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)
2 views19 pages

Practical 1,23 Full

The document provides an introduction to Database Management Systems (DBMS), detailing its role in data organization, security, integrity, and performance optimization. It discusses various DBMS software such as MySQL, Microsoft SQL Server, Oracle DBMS, MongoDB, and PostgreSQL, highlighting their features and licensing. Additionally, it covers SQL commands and their categories, including Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL), essential for managing databases.
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/ 19

CONTENTS

Sr
No, Name of Experiment Date Signature

pg. 1 DBMS Practical File Jagriti Sharma


PRACTICAL – 1A

1.1 INTRODUCTION TO DBMS


Database: The database is a collection of inter-related data which is used to retrieve, insert and
delete the data efficiently. It is also used to organize the data in the form of a table, schema, views,
and reports, etc

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.

• Database Management System


i. Database management system is a software which is used to manage the database. For
example: MySQL, Oracle, etc are a very popular commercial database which is used in
different applications.
ii. DBMS provides an interface to perform various operations like database creation, storing data
in it, updating data, creating a table in the database and a lot more.
iii. It provides protection and security to the database. In the case of multiple users, it also
maintains data consistency.

DBMS allows users the following tasks:

• 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.

pg. 2 DBMS Practical File Jagriti Sharma


1.2 SOFTWARE OF DBMS

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)

(ii) Microsoft SQL Server

Microsoft SQL Server is a comprehensive relational database management system developed by


Microsoft, designed to handle complex data
h storage and processing needs for enterprises. It offers
robust features including advanced security, high-performance querying, and seamless
integration with Microsoft ecosystem. The database system supports multiple deployment
options, from on-premises to cloud environments, providing flexible solutions for businesses of
all sizes across various industries.
• Developer: Microsoft Corporation
• Latest SQL Server long-term release: 2022
• Latest SQL Server release: 2022
• SQL Server license: Proprietary commercial software

(iii) Oracle DBMS


Oracle Database is a robust and sophisticated Relational Database Management System
(RDBMS) developed by Oracle Corporation, a global technology leader founded in 1977. The
database system has established itself as a premier solution for enterprise-level data
management, offering comprehensive capabilities for handling complex data storage,
retrieval, and processing needs. It supports multiple data types and workloads, making it
versatile for various business applications across industries. Oracle's architecture enables
efficient management of large data volumes, with advanced features like real-time analytics,
multi-model data support, and cloud compatibility. Developer: Oracle Corporation
• Latest Oracle DBMS long-term release: 19c
• Latest Oracle DBMS release: 19c
• Oracle DBMS license: Proprietary

pg. 3 DBMS Practical File Jagriti Sharma


(iv) MongoDB

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

PostgreSQL is a powerful, open-source object-relational database management system with over


35 years of active development. This robust database system offers exceptional flexibility,
reliability, and advanced features that make it a preferred choice for businesses and developers
worldwide. PostgreSQL distinguishes itself through its comprehensive feature set, including
support for complex SQL queries, advanced data types, and multi-version concurrency control. It
provides enterprise-grade capabilities such as robust transaction support, extensibility, and cross-
platform compatibility. The database system is continuously improved by a global community of
developers, ensuring ongoing innovation and reliability.
Major technology companies like AWS, Google, Microsoft, and Fujitsu actively contribute to
PostgreSQL's development, underscoring its significance in the global database ecosystem.
• Developer: PostgreSQL Global Development Group
• Latest PostgreSQL long-term release: 16
h
• Latest PostgreSQL release: 16
• PostgreSQL license: PostgreSQL License (open-source, permissive)

1.3 ROLE OF DBMS:

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.

3. Performance Optimization: By implementing advanced indexing techniques, query optimization,


and efficient data retrieval mechanisms, DBMS enhances overall system performance. It reduces data
redundancy, accelerates information processing, and supports complex computational
requirements.

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.

1.4 ROLE OF DBMS:

h of the primary needs for a DBMS is data organization


1. Data Organization and Management: One
and management. DBMSs allow data to be stored in a structured manner, which helps in easier
retrieval and analysis. A well-designed database schema enables faster access to information,
reducing the time required to find relevant data. A DBMS also provides features like indexing and
searching, which make it easier to locate specific data within the database. This allows organizations
to manage their data more efficiently and effectively.

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.

7. Cost-Effectiveness: DBMSs are cost-effective compared to traditional file-based systems. They


reduce storage costs by eliminating redundancy and optimizing data storage. They also reduce
development costs by providing tools for database design, maintenance, and administration.

1.5 QUERY AND CONCEPTS:

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 );

DROP Delete objects from the database DROP TABLE table_name;

ALTER Alter the structure of the database ALTER TABLE table_name ADD
COLUMN column_name data_type;

RENAME Rename an object existing in the RENAME TABLE


database old_table_name TO
new_table_name;

2. DML- Data Manipulation 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

pg. 6 DBMS Practical File Jagriti Sharma


against a table or tables the result is compiled into a further temporary table, which is displayed or
perhaps received by the program.

Command Description Syntax


INSERT Update existing data within a table INSERT INTO table_name
(column1, column2,...)
VALUES (value1, value2, ...);
UPDATE Update existing data within a table UPDATE table_name SET column1
= value1, column2 = value2
WHERE condition;
DELETE Delete records from a database table DELETE FROM table_name
WHERE condition;
LOCK Table control concurrency LOCK TABLE table_name IN
lock_mode;
CALL Call a PL/SQL or JAVA subprogram CALL procedure_name(arguments);

3. 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.

Command Description
h Syntax

GRANT Assigns new privileges to a GRANT privilege_type


user account, allowing access [(column_list)] ON
to specific database objects, [object_type] object_name TO
actions, or functions. user [WITH GRANT
OPTION];
REVOKE Removes previously granted REVOKE [GRANT OPTION
privileges from a user account, FOR] privilege_type
taking away their access to [(column_list)] ON
certain database objects or [object_type] object_name
actions. FROM user [CASCADE];

pg. 7 DBMS Practical File Jagriti Sharma


5. Transaction Control Language (TCL) in SQL

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

Command Description Syntax

BEGIN TRANSACTION Starts a new transaction BEGIN TRANSACTION


[transaction_name];
COMMIT Saves all changes made COMMIT;
during the transaction
ROLLBACK Saves all changes made ROLLBACK;
during the transaction
SAVEPOINT Creates a savepoint within the SAVEPOINT savepoint_name;
current transaction

Important SQL Commands

1. SELECT: Used to retrieve data from a database.

2. INSERT: Used to add new data to a database.


3. UPDATE: Used to modify existing data in a database.

4. DELETE: Used to remove data from a database.


h
5. CREATE TABLE: Used to create a new table in a database.

6. ALTER TABLE: Used to modify the structure of an existing table.

7. DROP TABLE: Used to delete an entire table from a database.

8. WHERE: Used to filter rows based on a specified condition.

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.

pg. 8 DBMS Practical File Jagriti Sharma


PRACTICAL – 1a: CREATING AND MANAGING TABLES

1.6AIM: To understand and implement SQL commands for:


i)Creating a database and tables v) Altering table structure
ii)Referencing another user's tables vi) Inserting and retrieving data
iii)Using the DEFAULT option vii) Dropping and truncating tables
iv) Data types and constraints

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:

Figure 1: creating Table- Employees

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

pg. 9 DBMS Practical File Jagriti Sharma


3. Inserting Records into the Table

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),

4 . Retrieving Data Using SELECT Query

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.

Figure 2: table- Employees

pg. 10 DBMS Practical File Jagriti Sharma


PRACTICAL 1b : Write SQL Queries for DROP , DELETE, ALTER
AND UPDATE

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.

Figure 3:Deleting a Table


h

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:

Figure 4: deleted from Employees Where Department = 'HR

The rows where Department = 'HR' are no longer present.

pg. 11 DBMS Practical File Jagriti Sharma


3.ALTER Statement
The ALTER statement is used to modify the structure of an existing table. It allows us to add, delete, or modify
columns without affecting the stored data.
Syntax: ALTER TABLE table_name ADD column_name data_type;
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE table_name MODIFY COLUMN column_name new_data_type;

SQL Query - ALTER TABLE Employees ADD Email VARCHAR(100);

Figure 5: Added column - Email

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;

Example- UPDATE Employees SET Salary = 80000 WHERE EmpID = 101;

Figure 6: Salary of employe (emp is1) is updated

pg. 12 DBMS Practical File Jagriti Sharma


PRACTICAL 2: Basic SQL SELECT Statements

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

1.Selecting All Columns:


n SQL, we can retrieve all the columns from a table using the SELECT * statement. This command fetches
every record and column from the specified table.. This is useful when all data from a table is required.
Example: SELECT * FROM Employees;

Figure 7:This query retrieves all columns from the "Employees" table.

2.Selecting Specific Columns:


Instead of retrieving all columns, we can fetch only the required columns for better efficiency and read -
bility.
Syntax- SELECT Name, Department, Salary FROM Employees;
Example: SELECT * FROM Employees;

Figure 8:query retrieves only the "Name," "Department," and "Salary" columns

pg. 13 DBMS Practical File Jagriti Sharma


3.Selecting Distinct Values from a Specific Column
To retrieve unique values from a column, we use the DISTINCT keyword. This helps eliminate duplicate
records in the output.
Example: SELECT DISTINCT City FROM Employees;

Figure 9:This query returns unique City names without repetition.

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.

Example - SELECT Name, Salary, Bonus, (Salary + Bonus) AS TotalEarnings


FROM Employees;

Figure 10:This query retrieves the employee’s name, salary, bonus, and calculates their total earnings using the addition operator.

pg. 14 DBMS Practical File Jagriti Sharma


C) COLUMN ALIASES
In SQL, column aliases are used to assign a temporary name to a column in the result set. Aliases make
output more readable, especially when dealing with complex expressions or when column names are long
and difficult to interpret.
Aliases are defined using the AS keyword, but it is optional. If the alias name contains spaces, double quotes
(" ") or square brackets ([ ]) are used.
Syntax: SELECT column_name AS alias_name FROM table_name;

Example- SELECT Name AS Employee_Name, Salary AS Monthly_Income FROM Employees;

Figure 11:Here, Name is displayed as 'Employee_Name', and Salary is displayed as 'Monthly_Income'

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

CONCAT(column1, ' ', column2) AS alias_name FROM table_name;


Example- SELECT Name || ' - ' || Department AS Employee_Details FROM Employees;

pg. 15 DBMS Practical File Jagriti Sharma


PRACTICAL 3: RESTRICTING AND SORTING DATA

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:

[A] BETWEEN Condition in SQL –

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.

Use Case of BETWEEN with Dates

We can also apply BETWEEN to date values. For example, to fetch students who joined between 2021-01-
01 and 2023-01-01

pg. 16 DBMS Practical File Jagriti Sharma


[B] IN OPERATOR IN SQL-
The IN operator is used to filter records based on multiple specified values. It acts as a shorthand for multiple
OR conditions, making queries more readable and efficient. It is commonly used for categorical data like
city names, departments, or student branches.
Syntax: SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, value3, ...);
Example – Retrieve students from the "Computer Science" and "Electronics" branches.
SELECT * FROM Students WHERE Branch IN ('Computer Science', 'Electronics');

Figure 13 students from Computer Science & Electronics branches.

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;

pg. 17 DBMS Practical File Jagriti Sharma


[D] OR Operator - The OR operator is used in the WHERE clause to filter records based on multiple
conditions. It returns results if at least one of the conditions is true. If both conditions are false, the row is
excluded from the result.
Syntax - SELECT column_name(s)
FROM table_name
WHERE condition1 OR condition2 OR condition3 ... ;
Example- SELECT * FROM Students WHERE Branch = 'Mechanical' OR City = 'Mumbai';

Figure 15: displaying Students WHERE Branch = 'Mechanical' OR City = 'Mumbai';

[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;

pg. 18 DBMS Practical File Jagriti Sharma


Example 1: Using % Wildcard , Retrieving all students whose names start with 'R'.
SELECT * FROM Students WHERE Name LIKE 'R%' ;

Figure 17: students whose names start with 'R'

Using _ Wildcard, Retrieving all students whose names have 'a' as the second letter.
SELECT * FROM Students WHERE Name LIKE '_a%' ;

Figure 18:students whose names have 'a' as the second letter.


h

[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

pg. 19 DBMS Practical File Jagriti Sharma

You might also like