Checked
Checked
Checked
OF
DATABASE MANAGEMENT SYSTEMS LAB
SESSION : 2024-25
Submitted By : Drishti Sharma
ii
Practical Page
S. No. Title of Practical Signature
Date No.
iii
Practical - 1
Aim: Write the queries for Data Definition Language (DDL) in RDBMS.
Data Definition Language (DDL): Data Definition Language (DDL) is a subset of SQL
(Structured Query Language) used to define and manage database structures, such as
tables, indexes, and schema. The primary DDL commands are CREATE, ALTER,
DROP, TRUNCATE, and RENAME. These commands allow users to define, modify, and
remove the structure of database objects but not data. These commands are normally not
used by a general user, who should be accessing the database via an application.
This guide will introduce you to the various SQL sublanguage commands,
including Data Definition Language (DDL), Data Query Language (DQL), Data
Manipulation Language (DML), Data Control Language (DCL), and Transaction Control
Language (TCL)
4. TRUNCATE: Used to remove all records from a table, but not the table itself.
5. DESCRIBE: Used to describe the structure of a table existing database object, such as a table.
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.
Data Manipulation Language (DML) is a subset of SQL used to retrieve, insert, update,
and delete data in a relational database. DML commands are used to manage the data
stored within database objects like tables. The primary DML commands are INSERT,
UPDATE, and DELETE. This guide will introduce you to the various SQL sublanguage
commands, including Data Definition Language (DDL), Data Query
Language (DQL), Data Manipulation Language (DML), Data Control Language (DCL),
and Transaction Control Language (TCL).
DML is an abbreviation for Data Manipulation Language. Represents a collection of
programming languages explicitly used to make changes to the database, such as: CRUD
operations to create, read, update and delete data.Data Manipulation Language, also known as
DML, is a set of sql command that are used to manipulate data within database tables or
query views. Data analysts, scientists, engineers, and anyone using SQL rely on DML in
order to access, transform, and analyze data. If you’ve ever worked with SQL, you’ve likely
used DML commands. If not, don’t worry—in the next section, I’ll explain DML commands
in more detail.
List of DML commands:
Data Control Language (DCL) is a subset of SQL that deals with the rights, permissions,
and control of access to data in an RDBMS. The primary DCL commands are GRANT
and REVOKE. These commands are used to give or remove access privileges to users on
database objects like tables, views, and procedures.
Integrity constraints are the set of predefined rules that are used to maintain the quality of
information. Integrity constraints ensure that the data insertion, data updating, data
deleting and other processes have to be performed in such a way that the data integrity is
not affected.
They act as guidelines ensuring that data in the database remain accurate and consistent.
So, integrity constraints are used to protect databases.
Integrity Constraints are the protocols that a table's data columns must follow. These are used to
restrict the types of information that can be entered into a table. This means that the data in the
database is accurate and reliable.
2. Not-Null Constraints: The Not-Null constraint ensures that a column cannot have a
NULL value, meaning data must be provided for this column.
3. Entity Integrity Constraints: Entity integrity ensures that each record in a table can be
uniquely identified. This is typically achieved through a Primary Key constraint. Entity
integrity constraints state that primary key can never contain null value because primary
key is used to determine individual rows in a relation uniquely, if primary key contains
null value then we cannot identify those rows. A table can contain null value in it except
primary key field.
4. Key Constraints: Key constraints define the uniqueness of data in certain columns.
Common key constraints are Primary Key and Unique Key. The Primary Key ensures
that no two records have the same value for the key column, while the Unique Key
ensures uniqueness but allows one NULL value.
Test For Key Constraints-
Relational Operations:
Use relational operators to filter data based on specific conditions.
Relational operators like =, ≠, ≥, <, >, <= AND, BETWEEN.
Practical No. – 5(b)
Aim: Create a database and perform Group by & having clauses.
The GROUP BY clause is often used with aggregate functions (MAX, SUM, AVG) to group the results by one
or more columns or In simple words we can say that The GROUP BY clause is used in collaboration with the
SELECT statement to arrange required data into groups.
Having Clause is basically like the aggregate function with the GROUP BY clause. The HAVING clause is
used instead of WHERE with aggregate functions.
Syntax:
SELECT column1, aggregate_function(column2)
FROM table_name
WHERE condition
GROUP BY column1, column2, ...;
Perform GROUP BY Clause:
Practical No. – 5(c)
Aim: Create a database and perform Like predicate for pattern matching in database.
Theory:
The LIKE predicate in SQL is used for pattern matching in strings. It allows us to search for a
specified pattern within a column's value. The LIKE operator is often used with the SELECT
statement to filter rows based on patterns.
Syntax of the LIKE Predicate:
SELECT column1, column2, ...
FROM table_name
WHERE column_name LIKE pattern;
Wildcards in the LIKE Predicate:
1. Percent Sign (%): Represents zero or more characters.
2. Underscore (_): Represents a single character.
Common Usage Patterns:
%pattern%: Matches any string that contains pattern anywhere.
pattern%: Matches any string that starts with pattern.
%pattern: Matches any string that ends with pattern.
_pattern_: Matches any string with exactly one character before and after pattern.
1. Match a String starting with a pattern:
To retrieve employees whose names start with the letter ‘A’:
2. Projection (π):
A relational algebra operation to retrieve specific columns (attributes) from a relation.
Equivalent SQL operation: SELECT column_names
3. Union (∪):
Combines tuples from two relations, removing duplicates.
Equivalent SQL operation: UNION
2. Left Join
Retrieves all rows from the left table and matching rows from the right table. Rows
with no match in the right table contain NULL.
3. Right Join
Retrieves all rows from the right table and matching rows from the left table. Rows
with no match in the left table contain NULL.
4. Full Join
A Full Join (or Full Outer Join) returns all rows from both tables, with matching
rows where available. If there is no match, the result will contain NULL in the
columns from the table that lacks the matching row.
However, MySQL does not support FULL OUTER JOIN natively. You can simulate
it using a combination of LEFT JOIN and RIGHT JOIN with a UNION.
Practical No. – 8
Aim: Write SQL queries for sub queries, nested queries.
Theory:
A subquery is a query nested inside another query, used to retrieve data that will be
used by the outer query. Subqueries can be used in SELECT, INSERT, UPDATE, and
DELETE statements.
There are two types of subqueries:
1. Single-row subquery: Returns a single value.
2. Multi-row subquery: Returns multiple rows.