0% found this document useful (0 votes)
3 views18 pages

DBMSPRACTICAL

Uploaded by

rohitk93639
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)
3 views18 pages

DBMSPRACTICAL

Uploaded by

rohitk93639
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/ 18

DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS)

(3IBCA 301)

A Practical file
Submitted in Partial Fulfillment of the Requirements for the Award of the Degree
of

BACHELOR OF COMPUTER APPLICATIONS (CS & IT)


(BATCH: 2023-2026 / 3rd Semester)

SUBMITTED BY

ROHIT KUMAR

_______________________________________________

ENROLLMENT NO. / ROLL NO.

CVB230045 / R23CA1CA0045

SUBMITTED TO

TAUQEER AKHTAR
ASSISTANT PROFESSOR, CSE DEPARTMENT

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


DR. C.V. RAMAN UNIVERSITY, VAISHALI, BIHAR
INDEX

Sr. Page Date of


Practical Faculty Sign
No. No. Practical

Write a query to implement Different


1.
types of DDL statements in SQL.

Write a query to implement Different


2.
types of DML statements in SQL.

Write a query to implement Different


3.
types of DQL statements in SQL.

Write a query to implement Different


4.
types of DCL statements in SQL.

Write a query to explore ‘select’ clause


5. using where, order by, between, like,
group-by, having etc.

Write a query to implement the concept


6.
of Joins in SQL.

Write a query to implement the concept


7.
of Indexes and views.

Write a query to implement the


8.
restrictions on the table.

Write a query to implement the concept


9.
of SubQuestionries.

Write a query to implement the


10.
structure of the table.
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

PRACTICAL 01

1. Different types of DDL (Data Definition Language) Statements in SQL

Step-by-Step:

1. Create Table:

o Step: Define the table structure including columns, data types, and

constraints.

sql code

CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY,

FirstName VARCHAR(50),

LastName VARCHAR(50),

Department VARCHAR(50)

); o Output: Creates a new table Employees with 4 columns.

2. Alter Table:

o Step: Add a new column to the table.

sql code

ALTER TABLE Employees ADD COLUMN DateOfBirth DATE; o

Output: Adds a new column DateOfBirth of type DATE.

3. Drop Table:

o Step: Delete an existing table from the database.

sql

code

1
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

DROP TABLE Employees; o Output: Removes the Employees

table from the database.

4. Create Index:

o Step: Create an index on the Department column for faster search.

sql

code

CREATE INDEX idx_department ON Employees(Department);

o Output: Creates an index called idx_department on the Department

column.

5. Drop Index:

o Step: Remove an index from the table.

sql

code

DROP INDEX idx_department; o Output: Drops

the idx_department index.

PRACTICAL 02

2. Different types of DML (Data Manipulation Language) Statements in

SQL

Step-by-Step:

1. Insert Data:

2
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

o Step: Add a new record into the Employees table.

sql

code

INSERT INTO Employees (EmployeeID, FirstName, LastName,

Department)

VALUES (1, 'John', 'Doe', 'IT');

o Output: Inserts a new employee record into the table.

2. Update Data:

o Step: Modify existing data in the table.

sql

code

UPDATE Employees

SET Department = 'HR'

WHERE EmployeeID = 1;

o Output: Updates the Department of the employee with EmployeeID 1 to

'HR'.

3. Delete Data:

o Step: Remove a record from the table.

sql

code

DELETE FROM Employees

WHERE EmployeeID = 1; o Output: Deletes the employee record

with EmployeeID 1.

3
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

PRACTICAL 03

3. Different types of DQL (Data Query Language) Statements in SQL

Step-by-Step:

1. Select All Data:

o Step: Retrieve all columns and rows from a table.

sql

code

SELECT * FROM Employees; o Output: Retrieves all rows and columns

from the Employees table.

2. Select Specific Columns:

o Step: Retrieve specific columns from a table.

sql

code

SELECT FirstName, LastName FROM Employees; o Output: Retrieves the

FirstName and LastName columns from all rows.

3. Select with WHERE Clause:

o Step: Filter rows based on a condition.

sql

code

SELECT * FROM Employees WHERE Department = 'IT';

o Output: Selects all rows where the Department is 'IT'.

4
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

4. Select with ORDER BY Clause:

o Step: Order the result set by one or more columns.

sql

code

SELECT * FROM Employees ORDER BY LastName; o Output: Orders the result

set by the LastName column in ascending order.

5. Select with LIMIT Clause:

o Step: Limit the number of rows returned.

sql

code

SELECT * FROM Employees LIMIT 5;

o Output: Retrieves only the first 5 rows from the Employees table.

PRACTICAL 04

4. Different types of DCL (Data Control Language) Statements in SQL

Step-by-Step:

1. Grant Permission:

o Step: Grant access rights (e.g., SELECT, INSERT) to a user.

sql

code

5
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

GRANT SELECT, INSERT ON Employees TO User1; o Output: Grants SELECT

and INSERT permissions on the Employees table to

User1.

2. Revoke Permission:

o Step: Revoke previously granted access rights.

sql

code

REVOKE SELECT, INSERT ON Employees FROM User1; o Output: Revokes

SELECT and INSERT permissions on the Employees table from User1.

PRACTICAL 05

5. Explore SELECT Clause using WHERE, ORDER BY, BETWEEN,

LIKE, GROUP BY, HAVING

Step-by-Step:

1. WHERE Clause:

o Step: Filter rows based on specific conditions.

sql

code

SELECT * FROM Employees WHERE Department = 'HR'; o

Output: Retrieves rows where the Department is 'HR'.

6
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

2. ORDER BY Clause:

o Step: Sort rows by one or more columns.

sql

code

SELECT * FROM Employees ORDER BY LastName DESC; o Output:

Orders the result set by LastName in descending order.

3. BETWEEN Clause:

o Step: Filter rows based on a range of values.

sql

code

SELECT * FROM Employees WHERE EmployeeID BETWEEN 1 AND 5; o Output:

Retrieves rows where EmployeeID is between 1 and 5 (inclusive).

4. LIKE Clause:

o Step: Filter rows based on a pattern.

sql

code

SELECT * FROM Employees WHERE FirstName LIKE 'J%';

o Output: Retrieves rows where FirstName starts with the letter 'J'.

5. GROUP BY Clause:

o Step: Group rows by a specific column and perform aggregate operations.

7
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

sql

code

SELECT Department, COUNT(*) FROM Employees GROUP BY Department;

o Output: Groups employees by Department and counts the number of

employees in each department.

6. HAVING Clause:

o Step: Filter results from GROUP BY with a condition.

sql

code

SELECT Department, COUNT(*) FROM Employees GROUP BY Department

HAVING COUNT(*) > 2;

o Output: Retrieves departments where the count of employees is greater than

2.

PRACTICAL 06

6. Concept of Joins in SQL

Step-by-Step:

1. INNER JOIN:

o Step: Combine rows from two tables where there is a match.

sql

code

8
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

SELECT Employees.FirstName, Employees.LastName,

Departments.DepartmentName

FROM Employees

INNER JOIN Departments ON Employees.Department =

Departments.DepartmentID;

o Output: Displays a list of employee names with their respective department

names.

2. LEFT JOIN:

o Step: Include all rows from the left table and matching rows from the right

table.

sql

code

SELECT Employees.FirstName, Employees.LastName,

Departments.DepartmentName

FROM Employees

LEFT JOIN Departments ON Employees.Department =

Departments.DepartmentID;

9
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

Output: Includes all employees, even if they do not have a matching

department.

3. RIGHT JOIN:

o Step: Include all rows from the right table and matching rows from the left

table.

sql

code

SELECT Employees.FirstName, Employees.LastName,

Departments.DepartmentName

FROM Employees

RIGHT JOIN Departments ON Employees.Department =

Departments.DepartmentID;

o Output: Includes all departments, even if no employees are assigned to

them.

4. FULL OUTER JOIN:

o Step: Include all rows from both tables, with NULLs where there is no

match.

sql

code

SELECT Employees.FirstName, Employees.LastName,

Departments.DepartmentName

FROM Employees

FULL OUTER JOIN Departments ON Employees.Department =

Departments.DepartmentID; o Output: Includes all employees and all

departments, showing NULL for unmatched records.

10
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

o
PRACTICAL 07

7. Concept of Indexes and Views

Step-by-Step:

1. Creating a View:

o Step: Create a virtual table (view) that simplifies complex queries.

sql

code

CREATE VIEW EmployeeView AS

SELECT EmployeeID, FirstName, LastName, Department

FROM Employees; o Output: A view called EmployeeView is created with

selected columns.

2. Querying a View:

o Step: Query the EmployeeView view like a normal table.

sql

code

SELECT * FROM EmployeeView; o Output: Displays data

from the view EmployeeView.

3. Creating an Index:

o Step: Create an index on the LastName column to speed up searches.

sql

code

11
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

CREATE INDEX idx_employee_name ON Employees(LastName);

Output: Creates an index on the LastName column.

4. Dropping an Index:

o Step: Drop the index when it's no longer needed.

sql

code

DROP INDEX idx_employee_name; o Output: Removes

the idx_employee_name index.

12
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

o
PRACTICAL 08

8. Restrictions on the Table

Step-by-Step:

1. PRIMARY KEY:

o Step: Create a table with a primary key to ensure uniqueness.

sql

code

CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY,

FirstName VARCHAR(50),

LastName VARCHAR(50)

); o Output: EmployeeID is the primary key, which ensures uniqueness.

2. UNIQUE Constraint:

o Step: Add a unique constraint to ensure no duplicate values in the

ProductName column.

sql

code

CREATE TABLE Products (

ProductID INT PRIMARY KEY,

ProductName VARCHAR(50) UNIQUE

); o Output: Ensures that each product name in the Products table is unique.

3. CHECK Constraint:

Step: Add a constraint to ensure OrderAmount is always greater than 0.

13
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

sql

code

CREATE TABLE Orders (

OrderID INT PRIMARY KEY,

OrderAmount DECIMAL CHECK (OrderAmount > 0)

); o Output: Ensures OrderAmount is always greater than 0.

4. NOT NULL Constraint:

o Step: Define columns that cannot contain NULL values.

sql

code

CREATE TABLE Customers (

CustomerID INT PRIMARY KEY,

FirstName VARCHAR(50) NOT NULL

); o Output: The FirstName column cannot have NULL values.

PRACTICAL 09

9. Concept of Subqueries

Step-by-Step:

1. Subquery in SELECT:

o Step: Use a subquery to filter results based on another query.

sql

code

SELECT FirstName, LastName

14
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

o
FROM Employees

WHERE EmployeeID IN (SELECT EmployeeID FROM Orders WHERE

OrderAmount > 100); o Output: Retrieves employees who made orders

greater than $100.

2. Subquery in FROM:

o Step: Use a subquery in the FROM clause to create a temporary result set.

sql

code

SELECT e.FirstName, e.LastName

FROM Employees e, (SELECT EmployeeID FROM Orders WHERE OrderAmount

> 100) o

WHERE e.EmployeeID = o.EmployeeID;

o Output: Retrieves employees who made orders greater than $100, using a

subquery.

15
DATA BASE MANAGEMENT SYSTEM (SQL/MS ACCESS) PRACTICAL FILE 3IBCA 301

PRACTICAL 10

10. Structure of the Table

Step-by-Step:

1. SHOW TABLE Structure:

o Step: View the structure of the Employees table (column names, types,

etc.).

sql

code

DESCRIBE Employees;

o Output: Displays the structure of the Employees table.

2. SHOW COLUMNS:

o Step: Use an alternative command to view table columns.

sql

code

SHOW COLUMNS FROM Employees; o Output: Displays columns,

data types, and other metadata.

16

You might also like