0% found this document useful (0 votes)
5 views

DBMS FILE

The document outlines various SQL concepts and commands, including Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL), explaining their purposes and common commands. It also covers query operations such as selection, projection, sorting, joins, nested queries, and set-oriented operations like union, difference, intersection, and division. Each experiment aims to teach practical applications of these concepts in relational database management systems.

Uploaded by

Vyomkesh Sharma
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)
5 views

DBMS FILE

The document outlines various SQL concepts and commands, including Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL), explaining their purposes and common commands. It also covers query operations such as selection, projection, sorting, joins, nested queries, and set-oriented operations like union, difference, intersection, and division. Each experiment aims to teach practical applications of these concepts in relational database management systems.

Uploaded by

Vyomkesh Sharma
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/ 17

Experiment No : 1

Objective: - Learn and apply the concept of Data Definition Language


(DDL) commands in RDBMS, Data Manipulation Language (DML) and
Data Control Language (DCL).

1. Data Definition Language (DDL)


DDL commands define the structure of a database and its objects, such as
tables, indexes, and views. They focus on creating, altering, and deleting these
elements. Common DDL commands include:
 CREATE: Creates a new table, database, index, or other database object.

 ALTER: Modifies an existing database object, such as adding or dropping


a column in a table.

 DROP: Deletes a table, database, index, or other database object.




 TRUNCATE: Removes all rows from a table, resetting it to an empty state.

2. Data Manipulation Language (DML)


DML commands are used to manipulate data stored in tables. These commands
allow for the insertion, update, and deletion of data. Common DML commands
include:
 INSERT: Adds new rows to a table.

 UPDATE: Modifies existing data in a table.


 DELETE: Removes rows from a table.

 SELECT (often classified separately as Query Language or SQL, but


commonly grouped with DML): Retrieves data from one or more tables.

3. Data Control Language (DCL)


DCL commands manage user permissions and control access to database
objects. They ensure data security by granting or revoking permissions. Common
DCL commands include:

 GRANT: Gives specific privileges to users or roles.

 REVOKE: Removes specific privileges from users or roles.


Applying the Concepts
To apply these concepts:
 Use DDL commands when setting up the database structure, like defining
tables and constraints.
 Use DML commands when inserting, updating, or deleting data within the
tables.
 Use DCL commands to control who can access and modify data or
database objects.
Experiment No : 2
Objective: - Simple queries: selection, projection, sorting on a simple
table, Small-large number of attributes, Distinct output values,
Renaming attributes, Computed attributes Simple-complex
conditions (AND, OR, NOT).

1. Selection
Selection involves retrieving specific rows from the table based on a condition.

2. Projection
Projection is used to retrieve specific columns from a table

3. Sorting
Sorting arranges the result set in a specific order, using ORDER BY.

4. Small-Large Number of Attributes


You can retrieve either a few or all attributes in the table.

5. Distinct Output Values


To get unique values in a column, use DISTINCT.

6. Renaming Attributes
Use AS to rename columns in the output.

7. Computed attributes:
This will display the Name and their salary after applying a 10% bonus.
8. Complex Conditions with AND:

8. Complex Conditions with OR:

9. Complex Conditions with NOT:


Experiment No : 3
Objective: - Partial Matching operators ( LIKE , % , _ ,*,? ), ASC-DESC
ordering combinations Checking for Nulls.

 LIKE: Used to find a pattern within text columns.


% (wildcard for zero or more characters): Matches any sequence of
characters (including no characters).

_ (single-character wildcard): Matches exactly one character.

Combining % and _:

2. ASC and DESC Ordering


You can use ORDER BY to sort the result set, and specify ASC (ascending) or DESC
(descending) order. Multiple columns can be sorted in different directions in the
same query.
3. Checking for Nulls
The IS NULL and IS NOT NULL operators check for null (missing) values in
columns.
 IS NULL: Checks if a column has a null value.

 IS NOT NULL: Checks if a column has a non-null value.


Experiment No : 4
Objective: - Multi-table queries (JOIN OPERATIONS), Simple joins (no
INNER JOIN) Aliasing tables – Full/Partial name qualification, Inner-
joins (two and more (different) tables), Inner-recursive- joins (joining
to itself), Outer-joins (restrictions as part of the HERE and ON clauses),
Using where & having clauses.

1. Simple Joins
Simple joins use conditions to relate columns from multiple tables. We use
aliases to make table references shorter.

2. Inner Join with Multiple Tables


An inner join with multiple tables is useful when querying information from
three or more tables.
3. Self-Join (Recursive Join)
A self-join is a join operation where a table joins to itself. Let’s assume we want
to find employees who report to a manager. We assume:
 ManagerID column in Employees references the ID of another employee
who is the manager.

4. Outer Joins (LEFT JOIN, RIGHT JOIN)


Outer joins include rows from one table even when there’s no match in the other
table. Use these for scenarios like finding employees who aren’t assigned to a
department or employees without projects.
 LEFT JOIN: Retrieves all employees and their departments. Employees
with no department show NULL for department-related fields.
 RIGHT JOIN: Retrieves all departments and employees in each
department, even if no employee is assigned.

5. Full Outer Join


Full outer joins combine all rows from both tables, with unmatched rows
showing NULL in columns for the other table. Not all RDBMS support FULL
OUTER JOIN.
Experiment No : 5
Objective: - Nested queries: In, Not In Exists, Not Exists Dynamic
relations (as part of SELECT, FROM, and WHERE clauses).

1. IN and NOT IN
IN and NOT IN are used to check if a value exists in a set of values returned by a
subquery.
Example: IN (Retrieve employees who are assigned to a project.)

Example: NOT IN (Retrieve employees who are not assigned to any project.)

2. EXISTS and NOT EXISTS


EXISTS and NOT EXISTS are used to check if a subquery returns any rows. They
are often more efficient than IN for complex queries, especially when working
with large datasets.
Example: EXISTS (Retrieve employees who belong to a department that has a
project.)
Example: NOT EXISTS (Retrieve departments that have no employees.)

3. Dynamic Relations in SELECT, FROM, and WHERE Clauses


Dynamic relations involve using subqueries within SELECT, FROM, or WHERE
clauses to generate data dynamically based on the results of other queries.
Example: Dynamic Subquery in SELECT
Retrieve each employee's name along with the number of projects they are
assigned to.
Example: Dynamic Subquery in FROM
Retrieve the department with the highest number of employees.

Example: Dynamic Subquery in WHERE


Retrieve projects where employees have a salary above the average salary.
Experiment No : 6
Objective: - Set Oriented Operations: Union, Difference, Intersection,
Division

1. Union
The UNION operation combines rows from two tables, removing duplicates,
and returns all unique rows from both queries.
Let’s say we want a combined list of all unique departments and all unique
project names.

2. Difference
The EXCEPT (or MINUS in some SQL dialects) operation returns rows from the
first query that are not in the second query.
For example, if we want to find employees who are not assigned to any
project, we can use EXCEPT.
3. Intersection
The INTERSECT operation returns rows that are common to both tables.
For instance, we can find employees who are also assigned to at least one
project.

4. Division
The DIVISION operation is useful when you want to find entities related to all
entities in another set. This is often simulated using JOIN, GROUP BY, and
HAVING clauses in SQL.

You might also like