Mca Dbms Lab Manual 2025
Mca Dbms Lab Manual 2025
SELECT Operation
Part – A:
From the above given tables perform the following queries:
1. Retrieve all data from table DEPOSIT.
Page 1 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Part – B:
1. Display all the details of first five customers from deposit table.
2. Display all the details of first three depositors from deposit table whose amount is greater than 1000.
3. Display Loan No, Customer Name of first five borrowers whose branch name does not belongs to ‘ANDHERI’
from borrow table.
4. Select all details with account numbers not in the range 105 to 109 in deposit table.
5. Select all records from BORROW where the amount is greater than 1000 and less than or equal to 7000, and
the loan number is between 250 and 600
Part – C:
1. Display all the detail of customer who deposited more than 5000 without using * from deposit table.
2. Retrieve all unique customer names with city. (Use Customer table)
3. Retrieve records from the BORROW table where the loan amount is greater than 3000 and the loan number
is not a multiple of 3.
4. Retrieve records from the DEPOSIT table where amount is greater than 2000 also account number is
between 100 and 110 and date is after '1-MAR-1995' or before '27-MAR-1996'.
5. Retrieve all odd/even value loan number from Borrow table
Lab 2 Perform SQL queries for Update, Alter, Rename, Delete, Truncate, Drop
Update Operation
Part – A:
From the above given tables perform the following queries (UPDATE Operation):
1. Update deposit amount of all customers from 3000 to 5000. (Use Deposit Table)
2. Change branch name of ANIL from VRCE to C.G. ROAD. (Use Borrow Table)
3. Update Account No of SANDIP to 111 & Amount to 5000. (Use Deposit Table)
4. Update amount of KRANTI to 7000. (Use Deposit Table)
Page 2 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
5. Update branch name from ANDHERI to ANDHERI WEST. (Use Branch Table)
6. Update branch name of MEHUL to NEHRU PALACE. (Use Deposit Table)
7. Update deposit amount of all depositors to 5000 whose account no between 103 & 107. (Use Deposit Table)
8. Update ADATE of ANIL to 1-4-95. (Use Deposit Table)
9. Update the amount of MINU to 10000. (Use Deposit Table)
10. Update deposit amount of PRAMOD to 5000 and ADATE to 1-4-96 (Use Deposit Table)
Part – B:
1. Give 10% Increment in Loan Amount. (Use Borrow Table)
2. Customer deposits additional 20% amount to their account, update the same. (Use Deposit Table)
3. Increase Amount by 1000 in all the account. (Use Deposit Table)
4. Update the BORROW table to set the amount to 7000 and the branch name to 'CENTRAL' where the customer
name is ‘MEHUL’ and the loan number is even.
5. Update the DEPOSIT table to set the date to '2022-05-15' and the amount to 2500 for all accounts in ‘VRCE’
and with an account number less than 105.
Part – C:
1. Update amount of loan no 321 to NULL. (Use Borrow Table)
2. Update branch name of KRANTI to NULL (Use Borrow Table)
3. Display the name of borrowers whose Loan number is NULL. (Use Borrow Table)
4. Display the Borrowers whose having branch. (Use Borrow Table)
5. Update the Loan Amount to 5000, Branch to VRCE & Customer Name to Darshan whose loan no is 481. (Use
Borrow Table)
6. Update the Deposit table and set the date to 01-01-2021 for all the depositor whose amount is less than
2000.
7. Update the Deposit table and set the date to NULL & Branch name to ‘ANDHERI whose Account No is 110.
Alter, Rename Operation
Part – A:
Use Deposit table of lab-1.
DEPOSIT
Column_Name DataType
ACTNO INT
CNAME VARCHAR(50)
BNAME VARCHAR(50)
AMOUNT DECIMAL(8,2)
ADATE DATETIME
From the above given tables perform the following queries (ALTER, RENAME Operation):
1. Add two more columns City VARCHAR (20) and Pincode INT.
2. Add column state VARCHAR(20).
3. Change the size of CNAME column from VARCHAR (50) to VARCHAR (35).
4. Change the data type DECIMAL to INT in amount Column.
5. Delete Column City from the DEPOSIT table.
6. Rename Column ActNo to ANO.
7. Change name of table DEPOSIT to DEPOSIT_DETAIL.
Part – B:
1. Rename Column ADATE to AOPENDATE OF DEPOSIT_DETAIL table.
2. Delete Column AOPENDATE from the DEPOSIT_DETAIL table.
3. Rename Column CNAME to CustomerName.
4. Add Column country.
Page 3 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Part – C:
Create following table using query according to the definition.
STUDENT_DETAIL
Column_Name DataType
Enrollment_No VARCHAR(20)
Name VARCHAR(25)
CPI DECIMAL(5,2)
Birthdate DATETIME
From the above given tables perform the following queries (ALTER, RENAME Operation):
1. Add two more columns City VARCHAR (20) (Not null) and Backlog INT (Null).
2. Add column department VARCHAR (20) Not Null.
3. Change the size of NAME column of student_detail from VARCHAR (25) to VARCHAR (35).
4. Change the data type DECIMAL to INT in CPI Column.
5. Delete Column City from the student_detail table.
6. Rename Column Enrollment_No to ENO.
7. Change name of table student_detail to STUDENT_MASTER.
DELETE, Truncate, Drop Operation
Part – A:
Use Deposit_Detail table (Altered table of DEPOSIT)
DEPOSIT_DETAIL
Column_Name DataType
ANO INT
CustomerName VARCHAR(35)
BNAME VARCHAR(50)
AMOUNT INT
PINCODE INT
1. Delete all the records of DEPOSIT_DETAIL table having amount less than and equals to 4000.
2. Delete all the accounts CHANDI BRANCH.
3. Delete all the accounts having account number (ANO) is greater than 102 and less than 105.
4. Delete all the accounts whose branch is ‘AJNI’ or ‘POWAI’
5. Delete all the accounts whose account number is NULL.
6. Delete all the remaining records using Delete command.
7. Delete all the records of Deposit_Detail table. (Use Truncate)
8. Remove Deposit_Detail table. (Use Drop)
Part – B:
Create following table using query according to the definition.
EMPLOYEE_MASTER
Column_Name DataType
EmpNo INT
EmpName VARCHAR(25)
JoiningDate DATETIME
Salary DECIMAL (8,2)
City VARCHAR(20)
Page 4 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 5 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
12. Display all the students whose name’s second character is vowel.
13. Display the name of students having no website and name consists of minimum five characters.
14. Display all the students whose last name starts with ‘Pat’.
15. Display all the students whose city name does not starts with ‘b’.
16. Display all the students whose student ID ends with digit.
17. Display all the students whose address does not contain any digit.
18. Find students whose first name starts with 'B', last name ends with 'A', and their website contains either 'math'
or 'science'. Ensure that their city does not start with 'B'.
19. Retrieve students who have 'Shah' in their last name and whose city ends with 'd'. Additionally, their website
should be either null or contain 'com'.
20. Select students whose first and second character is a vowel. Their city should start with 'R' and they must have
a website containing '.com'.
Part – B:
1. Display all the students whose name’s second character is vowel and of and start with H.
2. Display all the students whose last name does not ends with ‘a’.
3. Display all the students whose first name starts with consonant.
4. Retrieve student details whose first name starts with 'K', last name ends with 'tel', and either their website
contains 'tech' or they live in a city starting with 'R'.
5. Retrieve students whose address contains a hyphen '-' and whose city starts with either 'R' or 'B'. They must
have a website that ends with '.com' and their first name should not start with 'A'.
Part – C:
1. Display all the students whose address contains single quote or double quote.
2. Find students whose city does not contain the letter 'S' and their address contains either single or double
quotes. Their last name should start with 'P' and they must have a website that contains 'on'.
Lab 4 Perform SQL queries for Aggerate function and group by (without having)
Part – A:
Create table and inset records as per below.
EMP
EID EName Department Salary JoiningDate City Gender
101 Rahul Admin 56000 1-Jan-90 Rajkot Male
102 Hardik IT 18000 25-Sep-90 Ahmedabad Male
103 Bhavin HR 25000 14-May-91 Baroda Male
104 Bhoomi Admin 39000 8-Feb-91 Rajkot Female
105 Rohit IT 17000 23-Jul-90 Jamnagar Male
106 Priya IT 9000 18-Oct-90 Ahmedabad Female
107 Bhoomi HR 34000 25-Dec-91 Rajkot Female
1. Display the Highest, Lowest, Label the columns Maximum, Minimum respectively.
2. Display Total, and Average salary of all employees. Label the columns Total_Sal and Average_Sal, respectively.
3. Find total number of employees of EMPLOYEE table.
4. Find highest salary from Rajkot city.
5. Give maximum salary from IT department.
6. Count employee whose joining date is after 8-feb-91.
7. Display average salary of Admin department.
8. Display total salary of HR department.
9. Count total number of cities of employee without duplication.
10. Count unique departments.
11. Give minimum salary of employee who belongs to Ahmedabad.
Page 6 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 7 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
1. Display Count of Orders by Year and Region, Sorted by Year and Region
2. Display Regions with Maximum Sales Amount Exceeding 1000 in Any Year, Sorted by Region
3. Display Years with Total Sales Amount Less Than 10000, Sorted by Year Descending
4. Display Top 3 Regions by Total Sales Amount in Year 2024
5. Find the Year with the Lowest Total Sales Across All Regions.
Part – C:
1. Display Products with Average Sales Amount Between 1000 and 2000, Ordered by Product Name
2. Display Years with More Than 1 Orders from Each Region
3. Display Regions with Average Sales Amount Above 1500 in Year 2023 sort by amount in descending.
4. Find out region wise duplicate product.
5. Find out year wise duplicate product.
Lab 6 Implement SQL In-built functions (Math, String, and Date Functions)
Math functions
Part – A:
1. Display the result of 5 multiply by 30.
2. Find out the absolute value of -25, 25, -50 and 50.
3. Find smallest integer value that is greater than or equal to 25.2, 25.7 and -25.2.
4. Find largest integer value that is smaller than or equal to 25.2, 25.7 and -25.2.
5. Find out remainder of 5 divided 2 and 5 divided by 3.
6. Find out value of 3 raised to 2nd power and 4 raised 3rd power.
7. Find out the square root of 25, 30 and 50.
8. Find out the square of 5, 15, and 25.
9. Find out the value of PI.
10. Find out round value of 157.732 for 2, 0 and -2 decimal points.
11. Find out exponential value of 2 and 3.
12. Find out logarithm having base e of 10 and 2.
13. Find out logarithm having base b having value 10 of 5 and 100.
14. Find sine, cosine and tangent of 3.1415.
15. Find sign of -25, 0 and 25.
16. Generate random number using function.
Part – B:
Create and insert the following records in the EMP_MASTER table.
EmpNo EmpName JoiningDate Salary Commission City Dept Code
101 Keyur 5-1-02 12000.00 4500 Rajkot 3@g
102 Hardik 15-2-04 14000.00 2500 Ahmedabad 3@
103 Kajal 14-3-06 15000.00 3000 Baroda 3-GD
104 Bhoomi 23-6-05 12500.00 1000 Ahmedabad 1A3D
105 Harmit 15-2-04 14000.00 2000 Rajkot 312A
1. Display the result of Salary plus Commission.
2. Find smallest integer value that is greater than or equal to 55.2, 35.7 and -55.2.
3. Find largest integer value that is smaller than or equal to 55.2, 35.7 and -55.2.
4. Find out remainder of 55 divided 2 and 55 divided by 3.
5. Find out value of 23 raised to 2nd power and 14 raised 3rd power.
Part – C:
1. Retrieve the details of employees whose total earnings (Salary + Commission) are greater than 15000.
2. Find the details of employees whose commission is more than 25% of their salary.
Page 8 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
3. List the employees who joined before 2005 and whose total earnings (Salary + Commission) are greater than
15000.
4. Find employees whose total earnings (Salary + Commission) are at least double their salary.
String functions
Part – A:
1. Find the length of following. (I) NULL (II) ‘ hello ’ (III) Blank
2. Display your name in lower & upper case.
3. Display first three characters of your name.
4. Display 3rd to 10th character of your name.
5. Write a query to convert ‘abc123efg’ to ‘abcXYZefg’ & ‘abcabcabc’ to ‘ab5ab5ab5’ using REPLACE.
6. Write a query to display ASCII code for ‘a’,’A’,’z’,’Z’, 0, 9.
7. Write a query to display character based on number 97, 65,122,90,48,57.
8. Write a query to remove spaces from left of a given string ‘ hello world ‘.
9. Write a query to remove spaces from right of a given string ‘ hello world ‘.
10. Write a query to display first 4 & Last 5 characters of ‘SQL Server’.
11. Write a query to convert a string ‘1234.56’ to number (Use cast and convert function).
12. Write a query to convert a float 10.58 to integer (Use cast and convert function).
13. Put 10 space before your name using function.
14. Combine two strings using + sign as well as CONCAT ().
15. Find reverse of “Darshan”.
16. Repeat your name 3 times.
Part – B: Perform following queries on EMP_MASTER table.
1. Find the length of EMP Name and City columns.
2. Display EMP Name and City columns in lower & upper case.
3. Display first three characters of EMP Name column.
4. Display 3rd to 10th character of city column.
5. Write a query to display first 4 & Last 5 characters of EMP Name column.
Part – C: Perform following queries on EMP_MASTER table.
1. Put 10 space before EMP Name using function.
2. Combine EMP Name and city columns using + sign as well as CONCAT ().
3. Combine all columns using + sign as well as CONCAT ().
4. Combine the result as < EMP Name > Lives in <City>.
5. Combine the result as ‘EMP no of < EMP Name> is <EmpNo> .
6. Retrieve the names of all employee where the third character of the Name is a vowel.
7. Concatenate the name and city of students who have a name that ends with the letter 'r' and a city that starts
with 'R'.
Date Functions
Part – A:
1. Write a query to display the current date & time. Label the column Today_Date.
2. Write a query to find new date after 365 day with reference to today.
3. Display the current date in a format that appears as may 5 1994 12:00AM.
4. Display the current date in a format that appears as 03 Jan 1995.
5. Display the current date in a format that appears as Jan 04, 96.
6. Write a query to find out total number of months between 31-Dec-08 and 31-Mar-09.
7. Write a query to find out total number of hours between 25-Jan-12 7:00 and 26-Jan-12 10:30.
8. Write a query to extract Day, Month, Year from given date 12-May-16.
Page 9 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 10 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
PERSON
Column_Name DataType Constraints
PersonID Int Primary Key
PersonName Varchar (100) Not Null
DepartmentID Int Foreign Key, Null
Salary Decimal (8,2) Not Null
JoiningDate Datetime Not Null
City Varchar (100) Not Null
DEPT
Column_Name DataType Constraints
DepartmentID Int Primary Key
DepartmentName Varchar (100) Not Null, Unique
DepartmentCode Varchar (50) Not Null, Unique
Location Varchar (50) Not Null
Page 11 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
14. Find the average salary of a person who belongs to Ahmedabad city.
15. Produce Output Like: <PersonName> lives in <City> and works in <DepartmentName> Department. (In single
column)
Part – B:
1. Produce Output Like: <PersonName> earns <Salary> from <DepartmentName> department monthly. (In
single column)
2. Find city & department wise total, average & maximum salaries.
3. Find all persons who do not belong to any department.
4. Find all departments whose total salary is exceeding 100000.
Part – C:
1. List all departments who have no person.
2. List out department names in which more than two persons are working.
3. Give a 10% increment in the computer department employee’s salary. (Use Update)
Lab 9 Implement Advanced level Joins
Author Publisher
Column Name Data Type Constraints Column Name Data Type Constraints
AuthorID INT Primary Key PublisherID INT Primary Key
AuthorName VARCHAR(100) NOT NULL PublisherName VARCHAR(100) NOT NULL, UNIQUE
Country VARCHAR(50) NULL City VARCHAR(50) NOT NULL
Book
Column Name Data Type Constraints
BookID INT Primary Key
Title VARCHAR(200) NOT NULL
AuthorID INT Foreign Key, AUTHOR(AuthorID), NOT NULL
PublisherID INT Foreign Key, PUBLISHER(PublisherID), NOT NULL
Price DECIMAL(8,2) NOT NULL
PublicationYear INT NOT NULL
Page 12 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Part – A:
1. Display details of students who are from computer department.
Page 13 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Department
Column_Name DataType Constraints
DepartmentID Int Primary Key
DepartmentName Varchar (100) Not Null, Unique
Designation
Column_Name DataType Constraints
DesignationID Int Primary Key
DesignationName Varchar (100) Not Null, Unique
Page 14 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
3 HR 13 Clerk
4 Account 14 Manager
15 CEO
From the above given tables create Stored Procedures:
Part – A
1. Department, Designation & Person Table’s INSERT, UPDATE & DELETE Procedures.
2. Department, Designation & Person Table’s SELECTBYPRIMARYKEY
3. Department, Designation & Person Table’s (If foreign key is available then do write join and take columns on
select list)
4. Create a Procedure that shows details of the first 3 persons.
Part – B
1. Create a Proc that takes the dept name as input and returns a table with all workers working in that dept.
2. Create Procedure that takes department name & designation name as input and returns a table with worker’s
first name, salary, joining date & department name.
3. Create a Procedure that takes the first name as an input parameter and display all the details of the worker
with their department & designation name.
4. Create Procedure which displays department wise maximum, minimum & total salaries.
5. Create Procedure which displays designation wise average & total salaries.
Part – C
1. Create Procedure that Accepts Department Name and Returns Person Count.
2. Create a procedure that takes a salary value as input and returns all workers with a salary greater than input
salary value along with their department and designation details.
3. Create a procedure to find the department(s) with the highest total salary among all departments.
4. Create a procedure that takes a designation name as input and returns a list of all workers under that
designation who joined within the last 10 years, along with their department.
5. Create a procedure to list the number of workers in each department who do not have a designation assigned.
6. Create a procedure to retrieve the details of workers in departments where the average salary is above 12000.
Lab 12 Implement Advanced Stored Procedure
Departments
ColumnName DataType AN | NN Remarks
DepartmentID Int NN Primary Key
DepartmentName Varchar(100) NN
ManagerID Int NN
Location Varchar(100) NN
Employee
Column Name Data Type AN | NN Remarks
EmployeeID Int NN Primary Key
FirstName Varchar(100) NN
LastName Varchar(100) NN
DoB Datetime NN
Gender Varchar(50) NN
HireDate Datetime NN
DeptID Int NN Foreign Key
Salary Decimal(10,2) NN
Page 15 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Projects
ColumnName DataType AN | NN Remarks
ProjectID Int NN Primary Key
ProjectName Varchar(100) NN
StartDate Datetime NN
EndDate Datetime NN
DepartmentID Int NN Foreign Key
DepartmentID DepartmentName ManagerID Location
1 IT 101 New York
2 HR 102 San Francisco
3 Finance 103 Los Angeles
4 Admin 104 Chicago
5 Marketing 105 Miami
Part – A
1. Create Stored Procedure for Employee table As User enters either First Name or Last Name and based on this
you must give EmployeeID, DOB, Gender & Hiredate.
2. Create a Procedure that will accept Department Name and based on that gives employees list who belongs to
that department.
3. Create a Procedure that accepts Project Name & Department Name and based on that you must give all the
project related details.
4. Create a procedure that will accepts any integer and if salary is between provided integer, then those
employee list comes in output.
5. Create a Procedure that will accepts a date and gives all the employees who all are hired on that date.
Part – B
1. Create a Procedure that accepts Gender’s first letter only and based on that employee details will be served.
2. Create a Procedure that accepts First Name or Department Name as input and based on that employee data
will come.
3. Create a procedure that will accepts location, if user enters a location any characters, then he/she will get all
the departments with all data.
Page 16 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Part – C
1. Create a procedure that will accepts From Date & To Date and based on that he/she will retrieve Project
related data.
2. Create a procedure in which user will enter project name & location and based on that you must provide all
data with Department Name, Manager Name with Project Name & Starting Ending Dates.
Lab 13 Implement UDF
Note: for Table valued function use tables of Lab-2
Part – A
1. Write a function to print "hello world".
2. Write a function which returns addition of two numbers.
3. Write a function to check whether the given number is ODD or EVEN.
4. Write a function which returns a table with details of a person whose first name starts with B.
5. Write a function which returns a table with unique first names from the person table.
6. Write a function to print number from 1 to N. (Using while loop)
7. Write a function to find the factorial of a given integer.
Part – B
1. Write a function to compare two integers and return the comparison result. (Using Case statement)
2. Write a function to print the sum of even numbers between 1 to 20.
3. Write a function that checks if a given string is a palindrome
Part – C
1. Write a function to check whether a given number is prime or not.
2. Write a function which accepts two parameters start date & end date, and returns a difference in days.
3. Write a function which accepts two parameters year & month in integer and returns total days each year.
4. Write a function which accepts departmentID as a parameter & returns a detail of the persons.
5. Write a function that returns a table with details of all persons who joined after 1-1-1991.
Lab 14 Implement Cursor
Products
Column_Name DataType Constraints
Product_id Int Primary Key
Product_Name Varchar (250) Not Null
Price Decimal (10,2) Not Null
Products
Product_id Product_Name Price
1 Smatphone 35000
2 Laptop 65000
3 Headphones 5500
4 Television 85000
5 Gaming Console 32000
From the above given tables perform the following queries:
Part - A
1. Create a cursor Product_Cursor to fetch all the rows from a products table.
2. Create a cursor Product_Cursor_Fetch to fetch the records in form of ProductID_ProductName.
(Example: 1_Smartphone)
3. Create a Cursor to Find and Display Products Above Price 30,000.
4. Create a cursor Product_CursorDelete that deletes all the data from the Products table.
Page 17 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Part – B
1. Create a cursor Product_CursorUpdate that retrieves all the data from the products table and increases the
price by 10%.
2. Create a Cursor to Rounds the price of each product to the nearest whole number.
Part – C
1. Create a cursor to insert details of Products into the NewProducts table if the product is “Laptop” (Note:
Create NewProducts table first with same fields as Products table)
2. Create a Cursor to Archive High-Price Products in a New Table (ArchivedProducts), Moves products with a
price above 50000 to an archive table, removing them from the original Products table.
Lab 15 Implement Trigger
Create following table (Using Design Mode)
PersonInfo
Column_Name DataType Constraints
PersonID Int Primary Key
PersonName Varchar (100) Not Null
Salary Decimal (8,2) Not Null
JoiningDate Datetime Allow Null
City Varchar (100) Not Null
Age Int Allow Null
BirthDate Datetime Not Null
PersonLog
Column_Name DataType Constraints
PLogID Int Primary Key, Auto increment
PersonID Int Not Null
PersonName Varchar (250) Not Null
Operation Varchar (50) Not Null
UpdateDate Datetime Not Null
Page 18 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
EmployeeLogs
Column_Name DataType Constraints
LogID Int Primary Key, Autoincrement
EmployeeID Int Not Null
EmployeeName Varchar(100) Not Null
ActionPerformed Varchar(100) Not Null
ActionDate DateTime Not Null
Part – A
1. Create a trigger that fires AFTER INSERT, UPDATE, and DELETE operations on the EmployeeDetails table to
display the message "Employee record affected.”
2. Create a trigger that fires AFTER INSERT, UPDATE, and DELETE operations on the EmployeeDetails table to log
all operations into the EmployeeLog table.
3. Create a trigger that fires AFTER INSERT to automatically calculate the joining bonus (10% of the salary) for
new employees and update a bonus column in the EmployeeDetails table.
Part – B
1. Create a trigger to ensure that the JoiningDate is automatically set to the current date if it is NULL.
Part – C
1. Create a trigger that ensure that ContactNo is valid during insert and update (ContactNo length is 10)
Instead of Trigger
Movies
Column_Name DataType Constraints
MovieID INT PRIMARY KEY
MovieTitle VARCHAR(255) NOT NULL
ReleaseYear INT NOT NULL
Genre VARCHAR(100) NOT NULL
Rating DECIMAL(3,1) NOT NULL
Duration INT NOT NULL – (In minutes)
MoviesLog
Column_Name DataType Constraints
LogID INT PRIMARY KEY,AUTO INCREMENT
Page 19 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Orders
Column_Name DataType Constraints
Order_id Int Primary Key
Customer_id Int Foreign Key
Order_date date Not Null
From the above given tables perform the following queries:
Part – A
1. Handle Divide by Zero Error and Print message like: Error occurs that is - Divide by zero error.
2. Try to convert string to integer and handle the error using try…catch block.
3. Create a procedure that prints the sum of two numbers: take both numbers as integer & handle exception
with all error functions if any one enters string value in numbers otherwise print result.
4. Handle a Primary Key Violation while inserting data into customers table and print the error details such as
the error message, error number, severity, and state.
5. Throw custom exception using stored procedure which accepts Customer_id as input & that throws Error like
no Customer_id is available in database.
Part – B
1. Handle a Foreign Key Violation while inserting data into Orders table and print appropriate error message.
2. Throw custom exception that throws error if the data is invalid.
3. Create a Procedure to Update Customer’s Email with Error Handling
Part – C
1. Create a procedure which prints the error message that “The Customer_id is already taken. Try another one”.
2. Handle Duplicate Email Insertion in Customers Table.
Lab 18 Perform SQL queries to implement constraints
Part – A:
Create below table with following constraints
Page 20 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
STU_MASTER
Rno(PK) Name Branch SPI Bklog
101 Raju CE 8.80 0
102 Amit CE 2.20 3
103 Sanjay ME 1.50 6
104 Neha EC 7.65 0
105 Meera EE 5.52 2
106 Mahesh 4.50 3
Part – B: Create table as per following schema with proper validation and try to insert data which violate your
validation.
1. Emp_details(Eid, Ename, Did, Cid, Salary, Experience)
Dept_details(Did, Dname)
City_details(Cid, Cname)
Part – C: Create table as per following schema with proper validation and try to insert data which violate your
validation.
1. Emp_info(Eid, Ename, Did, Cid, Salary, Experience)
Dept_info(Did, Dname)
City_info(Cid, Cname, Did))
District(Did, Dname, Sid)
State(Sid, Sname, Cid)
Country(Cid, Cname)
2. Insert 5 records in each table.
3. Display employeename, departmentname, Salary, Experience, City, District, State and country of all
employees.
Lab 19 Perform following queries using use, drop, createcollection, dropcollection, insertOne and insertMany method.
Part - A
1. Create a new database named “Darshan”.
2. Create another new database named “DIET”.
3. List all databases.
4. Check the current database.
5. Drop “DIET” database.
6. Create a collection named “Student” in the “Darshan” database.
7. Create a collection named “Department” in the “Darshan” database.
8. List all collections in the “Darshan” database.
9. Insert a single document using insertOne into “Department” collection. (Dname:’CE’, HOD:’Patel’)
10. Insert two document using insertMany into “Department” collection. (Dname:’IT’ and Dname:’ICT’)
11. Drop a collection named “Department” from the “Darshan” database.
12. Insert a single document using insertOne into “Student” collection.
(Fields are Name, City, Branch, Semester, Age) Insert your own data.
13. Insert three documents using insertMany into “Student” collection.
Page 21 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
(Fields are Name, City, Branch, Semester, Age) Insert your three friend’s data.
14. Check whether “Student” collection exists or not.
15. Check the stats of “Student” collection.
16. Drop the “Student” collection.
17. Create a collection named “Deposit”.
18. Insert following data in to “Deposit” collection.
Deposit
ACTNO CNAME BNAME AMOUNT CITY
101 ANIL VRCE 1000.00 RAJKOT
102 SUNIL AJNI 5000.00 SURAT
103 MEHUL KAROLBAGH 3500.00 BARODA
104 MADHURI CHANDI 1200.00 AHMEDABAD
105 PRMOD M.G. ROAD 3000.00 SURAT
106 SANDIP ANDHERI 2000.00 RAJKOT
107 SHIVANI VIRAR 1000.00 SURAT
108 KRANTI NEHRU PLACE 5000.00 RAJKOT
19. Display all the documents of “Deposit” collection.
20. Drop the “Deposit” collection.
Part – B
1. Create a new database named “Computer”.
2. Create a collection named “Faculty” in the “Computer” database.
3. Insert a below document using insertOne into “Faculty” collection.
Faculty
FID FNAME BNAME SALARY JDATE
1 ANIL CE 10000 1-3-95
4. Insert below documents using insertMany into “Faculty” collection.
Faculty
FID FNAME BNAME SALARY JDATE
2 SUNIL CE 50000 4-1-96
3 MEHUL IT 35000 17-11-95
4 MADHURI IT 12000 17-12-95
5 PRMOD CE 30000 27-3-96
6 SANDIP CE 20000 31-3-96
7 SHIVANI CE 10000 5-9-95
8 KRANTI IT 50000 2-7-95
5. Display all the documents of “Faculty” collection.
6. Drop the “Faculty” collection.
7. Drop the “Computer” database.
Part – C (Perform following operation using UI)
1. Create a new database named “Computer”.
2. Create a collection named “Faculty” in the “Computer” database.
3. Insert a below documents into “Faculty” collection.
Faculty
FID FNAME BNAME SALARY JDATE
1 ANIL CE 10000 1-3-95
2 SUNIL CE 50000 4-1-96
3 MEHUL IT 35000 17-11-95
4 MADHURI IT 12000 17-12-95
Page 22 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 23 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 24 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 25 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
15. Delete all students who are not in the cities 'Rajkot', 'Baroda', or 'Jamnagar'.
16. Delete students whose Rollno is between 105 and 108.
17. Rename the City field to LOCATION for all students.
18. Rename the Department field to Branch where the Fees is less than 10000.
19. Rename Sname to Fullname for students with Rollno in [106, 107, 108].
20. Rename Fees to Tuition_Fees for all students with Fees greater than 9000.
21. Rename Department to Major where the Fees is less than 15000 and Gender is 'Female'.
22. Rename City to Hometown for all students whose SEM is 3 and Department is not 'Mechanical'.
Part – C
1. Create a capped collection named” logs” with a maximum size of 100 KB and a maximum of 10 documents.
2. Insert below 12 log entries into the “logs” collection. Each entry should contain a message, level (e.g., "info",
"warning", "error"), and a timestamp field. Use the insertMany() method.
{ message: "System started", level: "info", timestamp: new Date() }
{ message: "Disk space low", level: "warning", timestamp: new Date() }
{ message: "User login", level: "info", timestamp: new Date() }
{ message: "System reboot", level: "info", timestamp: new Date() }
{ message: "Error in module", level: "error", timestamp: new Date() }
{ message: "Memory usage high", level: "warning", timestamp: new Date() }
{ message: "User logout", level: "info", timestamp: new Date() }
{ message: "File uploaded", level: "info", timestamp: new Date() }
{ message: "Network error", level: "error", timestamp: new Date() }
{ message: "Backup completed", level: "info", timestamp: new Date() }
{ message: "Database error", level: "error", timestamp: new Date() }
{ message: "Service started", level: "info", timestamp: new Date() }
3. Perform find method on “logs” collection to ensure only the last 10 documents are retained (even though
you inserted 12).
4. Insert below 5 more documents and check if the oldest ones are automatically removed.
{ message: "New log entry 1", level: "info", timestamp: new Date() }
{ message: "New log entry 2", level: "info", timestamp: new Date() }
{ message: "New log entry 3", level: "info", timestamp: new Date() }
{ message: "New log entry 4", level: "warning", timestamp: new Date() }
{ message: "New log entry 5", level: "error", timestamp: new Date() }
Lab 22 Perform the following queries using Regex:
Part – A Create collection named “Employee” and insert following 10 documents into it.
employee
EID ENAME GENDER JOININGDATE SALARY CITY
1 Nick Male 01-JAN-13 4000 London
2 Julian Female 01-OCT-14 3000 New York
3 Roy Male 01-JUN-16 3500 London
4 Tom Male NULL 4500 London
5 Jerry Male 01-FEB-13 2800 Sydney
6 Philip Male 01-JAN-15 7000 New York
7 Sara Female 01-AUG-17 4800 Sydney
8 Emily Female 01-JAN-15 5500 New York
9 Michael Male NULL 6500 London
10 John Male 01-JAN-15 8800 London
Page 26 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 27 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
6. Display name, sem, fees, and department whose city contains ‘med’ as three letters somewhere in city
name.
7. Display name, sem, fees, and department who does not belongs to city Rajkot or Baroda.
8. Find students whose names start with 'K' and are followed by any character.
9. Find students whose names end with 'a'.
10. Find students whose names contain 'ri'. (case-insensitive)
Part – C
1. Find students whose names start with a vowel (A, E, I, O, U).
2. Find students whose CITY ends with 'pur' or 'bad'.
3. Find students whose FEES starts with '1'.
4. Find students whose SNAME starts with 'K' or 'V'.
5. Find students whose CITY contains exactly five characters.
6. Find students whose names do not contain the letter 'e'.
7. Find students whose CITY starts with 'Ra' and ends with 'ot'.
8. Find students whose names contain exactly one vowel.
9. Find students whose names start and end with the same letter.
10. Find students whose DEPARTMENT starts with either 'C' or 'E'.
11. Find students whose SNAME has exactly 5 characters.
12. Find students whose GENDER is Female and CITY starts with 'A'.
Lab 23 Perform the following queries using Regex:
Part – A Create collection named “Customer” and insert following 10 documents into it.
CID CNAME EMAIL GENDER CITY BALANCE
1 Rajesh [email protected] Male Surat 5000
2 Meena [email protected] Female Ahmedabad 8000
3 Anil [email protected] Male Vadodara 6000
4 Sneha [email protected] Female Rajkot 50000
5 Nikhil [email protected] Male Surat 4000
6 Rachna [email protected] Female Baroda 9000
7 Gaurav [email protected] Male Jamnagar 10000
8 Tanya [email protected] Female Mehsana 5500
9 Pushti [email protected] Female Rajkot 50000
10 Avni [email protected] Female Morbi 10000
Part – B Create collection named “Company” and insert following 10 documents into it.
CID CNAME EMAIL INDUSTRY CITY EMPLOYEES
1 TechNova [email protected] IT Bangalore 250
Page 28 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 29 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 30 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
"sales": 200000,
"profit": 15000
}
{ "_id": 4,
"company": "Company-D",
"sector": "Technology",
"eps": 5.2,
"pe": 15.3,
"roe": 12.8,
"sales": 300000,
"profit": 25000
}
{ "_id": 5,
"company": "Company-E",
"sector": "Finance",
"eps": 7.1,
"pe": 12.4,
"roe": 10.9,
"sales": 450000,
"profit": 40000
}
{ "_id": 6,
"company": "Company-F",
"sector": "Healthcare",
"eps": 3.8,
"pe": 18.9,
"roe": 9.5,
"sales": 500000,
"profit": 35000
}
{ "_id": 7,
"company": "Company-G",
"sector": "Retail",
"eps": 4.3,
"pe": 22.1,
"roe": 14.2,
"sales": 600000,
"profit": 45000
}
{
"_id": 8,
"company": "Company-H",
"sector": "Energy",
"eps": 6.5,
"pe": 10.5,
"roe": 16.4,
"sales": 550000,
Page 31 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
"profit": 50000
}
{
"_id": 9,
"company": "Company-I",
"sector": "Consumer Goods",
"eps": 2.9,
"pe": 25.3,
"roe": 7.8,
"sales": 350000,
"profit": 20000
}
3. Calculate the total sales of all companies.
4. Find the average profit for companies in each sector.
5. Get the count of companies in each sector/
6. Find the company with the highest PE ratio.
7. Filter companies with PE ratio greater than 20.(Use: Aggregate)
8. Calculate the total profit of companies with sales greater than 250,000.
9. Project only the company name and profit fields.(Use: Aggregate)
10. Find companies where EPS is greater than the average EPS.
11. Group companies by sector and get the maximum sales in each sector.
12. Calculate the total sales and total profit of companies in each sector.
13. Sort companies by profit in descending order.(Use: Aggregate)
14. Find the average ROE across all companies.
15. Group companies by sector and calculate both the minimum and maximum EPS.
Part – C
1. Count the number of companies with profit greater than 30,000.
2. Get the total profit by sector and sort by descending total profit.
3. Find the top 3 companies with the highest sales.
4. Calculate the average PE ratio of companies grouped by sector.
5. Get the sum of sales and profit for each company.
6. Find companies with sales less than 400,000 and sort them by sales.
7. Group companies by sector and find the total number of companies in each sector.
8. Get the average ROE for companies with sales greater than 200,000.
9. Find the maximum profit in each sector.
10. Get the total sales and count of companies in each sector.
11. Project fields where profit is more than 20,000 and only show company and profit.
12. Find companies with the lowest ROE and sort them in ascending order.(Use: Aggregate)
Lab 25 Perform the following queries using Aggregate:
Part – A Create collection named “Faculty” and insert following 10 documents into it.
Faculty
FID FNAME DEPARTMENT SALARY EXPERIENCE GENDER CITY
201 Aarti CE 50000 5 Female Rajkot
202 Bhavesh EC 45000 7 Male Ahmedabad
203 Chitra Civil 40000 6 Female Baroda
204 Deepak CE 50000 8 Male Rajkot
205 Ekta CE 52000 4 Female Jamnagar
Page 32 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 33 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Running
104 Raj Mehta Footwear 3000 2 6000 2025-05-16 Delivered
Shoes
105 Zarna Modi Book Set Stationery 1200 1 1200 2025-05-18 Delivered
Mehul Bluetooth
106 Electronics 2500 1 2500 2025-05-20 Shipped
Joshi Speaker
107 Sneha Rana Handbag Fashion 1800 2 3600 2025-05-22 Delivered
103 Nidhi Desai Laptop Electronics 65000 1 65000 2025-05-19 Delivered
101 Riya Shah iPhone 13 Electronics 70000 1 70000 2025-05-10 Delivered
102 Amit Patel T-shirt Fashion 500 3 1500 2025-05-12 Shipped
Page 34 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Manager
MANAGER_ID NAME EMAIL PHONE
101 John Smith [email protected] 123-456-7890
102 Alice Brown [email protected] 234-567-8901
103 Carol White [email protected] 345-678-9012
104 David Green [email protected] 456-789-0123
105 Emma Black [email protected] 567-890-1234
Department
DEPARTMENT HEAD_MANAGER_ID
Marketing 101
IT 102
R&D 103
Finance 105
HR 106
Page 35 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 36 of 37
Master of Computer Applications
A.Y. 2025 | Semester - I
Lab Manual
2305CS101 – Database Management System
Page 37 of 37