DBMS Manual
DBMS Manual
Affiliated to VTU, Belagavi | Approved by AICTE, New Delhi | Recognized by UGC under (2f) |
Recognized by Govt. of Karnataka
Department of IS&E
LABORATORY MANUAL
DATABASE
MANAGEMENT SYSTEMS
BCS403
2023-2024
1
PREPARED BY:
Mrs. Meghana G R, Asst. Prof., Department of IS&E
Vision and Mission of the Institution
PSO2 Software Development and Entrepreneurship for Successful Career: Analyze, design and
develop data-driven software systems and applications that harness the power of emerging
computing technologies for successful career.
PEO1 Graduates from the Information Science & Engineering program should demonstrate
professional excellence by applying their knowledge and skills to address real-world
challenges in the field.
@# 16032024 3
IPCC (26.04.2022)
passing mark for the CIE is 40% of the maximum marks (20 marks out of 50) and for the SEE minimum passing mark is
35% of the maximum marks (18 out of 50 marks). A student shall be deemed to have satisfied the academic requirements
and earned the credits allotted to each subject/ course if the student secures a minimum of 40% (40 marks out of 100) in
the sum total of the CIE (Continuous Internal Evaluation) and SEE (Semester End Examination) taken together.
CIE for the theory component of the IPCC (maximum marks 50)
● IPCC means practical portion integrated with the theory of the course.
● CIE marks for the theory component are 25 marks and that for the practical component is 25 marks.
● 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests, each of 15
Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment methods mentioned in
22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second test after covering 85-90% of
the syllabus.
● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the theory
component of IPCC (that is for 25 marks).
● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.
CIE for the practical component of the IPCC
● 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks for the test to be
conducted after the completion of all the laboratory sessions.
● On completion of every experiment/program in the laboratory, the students shall be evaluated including viva-voce
and marks shall be awarded on the same day.
● The CIE marks awarded in the case of the Practical component shall be based on the continuous evaluation of the
laboratory report. Each experiment report can be evaluated for 10 marks. Marks of all experiments’ write-ups are
added and scaled down to 15 marks.
● The laboratory test (duration 02/03 hours) after completion of all the experiments shall be conducted for 50 marks
and scaled down to 10 marks.
● Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory component of IPCC
for 25 marks.
● The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCC.
SEE for IPCC
Theory SEE will be conducted by University as per the scheduled timetable, with common question papers for the course
(duration 03 hours)
1. The question paper will have ten questions. Each question is set for 20 marks.
2. There will be 2 questions from each module. Each of the two questions under a module (with a maximum of 3 sub-
questions), should have a mix of topics under that module.
3. The students have to answer 5 full questions, selecting one full question from each module.
4. Marks scoredby the student shall be proportionally scaled down to 50 Marks
The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical portion will have a CIE
component only. Questions mentioned in the SEE paper may include questions from the practical component.
Suggested Learning Resources:
Text Books:
1. Fundamentals of Database Systems, Ramez Elmasri and Shamkant B. Navathe, 7th Edition, 2017, Pearson.
2. Database management systems, Ramakrishnan, and Gehrke, 3rd Edition, 2014, McGraw Hill
Activity Based Learning (Suggested Activities in Class)/ Practical Based learning
Mini Project:
• Project Based Learning
@# 16032024 4
1. Create a table called Employee & execute the following.
Solution:
FLUSH PRIVILEGES;
Create the Employee table and insert three records using rollback:
EMPNO INT,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MANAGER_NO INT,
COMMISSION DECIMAL(10, 2)
);
desc Employee
2
Field Type Null Key Default
ENAME varchar(50) Yes NULL
insert into Employee values (1, 'John Doe', 'Manager', NULL, 5000.00, 1000.00),
insert into Employee values (2, 'Jane Smith', 'Developer', 1, 4000.00, NULL),
insert into Employee values (3, 'Alice Johnson', 'Salesperson', 1, 3000.00, 500.00);
ROLLBACK;
2. Add primary key constraint and not null constraint to the Employee table
Add primary key constraint
ALTER TABLE Employee ADD PRIMARY KEY (EMPNO);
3
ALTER TABLE Employee
MODIFY ENAME VARCHAR(50) NOT NULL,
MODIFY JOB VARCHAR(50) NOT NULL,
MODIFY SAL DECIMAL(10,2) NOT NULL;
Output:
4
2. Create a table called Employee that contain attributes EMPNO, ENAME,JOB, MGR,SAL &
execute the following.
CREATE TABLE Employee (
EMPNO INT,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MGR INT,
SAL DECIMAL(10,2)
);
desc Employee
6
DELETE FROM Employee
WHERE EMPNO2 = 105;
Select * from Employee
7
3. Queries using aggregate functions(COUNT,AVG,MIN,MAX,SUM),Group by,Orderby.
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
2 Alice 32 35700.00
3 Bob 28 28000.00
4 Charles 30 32000.00
total_employees
4
8
max_age
35
min_age
28
SELECT Salary
FROM Employee
ORDER BY Salary ASC;
Salary 1
28000.00
32000.00
35700.00
40000.00
2 Alice 32 35700.00
3 Bob 28 28000.00
4 Charles 30 32000.00
6 peter 38 40000.00
9
Salary num_employees
28000.00 1
32000.00 1
35700.00 1
40000.00 2
10
4. Create a row level trigger for the customers table that would fire for INSERT or UPDATE
or DELETE operations performed on the CUSTOMERS table. This trigger will display
the salary difference between the old & new Salary.
CUSTOMERS(ID,NAME,AGE,ADDRESS,SALARY)
First, create an audit table to store the salary differences and other relevant information.
11
Step 2: Create Triggers
Next, create the triggers for INSERT, UPDATE, and DELETE operations to log changes to the
customers_audit table.
DELIMITER //
DELIMITER ;
DELIMITER //
DELIMITER ;
12
Trigger for DELETE
DELIMITER //
DELIMITER ;
Output:
3 rows inserted
13
1 INSERT 1 NULL 100000.00 NULL 2024-05-20
14:20:09
2 INSERT 2 NULL 92000.00 NULL 2024-05-20
14:20:09
3 INSERT 3 NULL 45000.00 NULL 2024-05-20
14:20:09
14
Delete a row with id 1
Output:
15
5. Create cursor for Employee table & extract the values from the table. Declare the variables
Open the cursor & extrct the values from the cursor. Close the cursor.
Employee(E_id, E_name, Age, Salary)
E_name VARCHAR(255),
Age INT,
Salary DECIMAL(10, 2)
);
desc employee;
VALUES
16
3. Procedure to create routine:
DELIMITER //
BEGIN
END //
DELIMITER ;
BEGIN
17
DECLARE employee_cursor CURSOR FOR
OPEN employee_cursor;
read_loop: LOOP
IF done THEN
LEAVE read_loop;
END IF;
CLOSE employee_cursor;
END
CALL ExtractEmployeeData();
18
6. Write a PL/SQL block of code using parameterized Cursor, that will merge the
data available in the newly created table N_RollCall with the data available in
the table O_RollCall. If the data in the first table already exist in the second
table then that data should be skipped.
Creation of Tables:
CREATE TABLE N_RollCall (
student_id INT,
rollcall_date DATE,
status VARCHAR(10),
PRIMARY KEY (student_id, rollcall_date)
);
Insertion of values
-- Insert sample data into N_RollCall
INSERT INTO N_RollCall (student_id, rollcall_date, status) VALUES
(1, '2024-06-25', 'Present'),
(2, '2024-06-25', 'Absent'),
(3, '2024-06-25', 'Present');
Creation of Procedure
DELIMITER $$
19
CREATE PROCEDURE merge_rollcall()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE v_student_id INT;
DECLARE v_rollcall_date DATE;
DECLARE v_status VARCHAR(10);
20
END LOOP;
DELIMITER ;
7. Install an Open Source NoSQL Data base MongoDB & perform basic
CRUD(Create, Read, Update & Delete) operations. Execute MongoDB basic
Queries using CRUD operations.
2. Insert Operation:
db.users.insertOne({
name: "Braham Kumar",
age: 25,
email: "[email protected]",
status: "inactive"
});
◉ Insert multiple documents:
db.users.insertMany([
{
name: "Braham Kumar",
age: 25,
email: "[email protected]",
status: "inactive"
},
{
21
name: "Shubham Kumar",
age: 35,
email: "[email protected]",
status: "active"
},
{
name: "Bikash Singh",
age: 28,
email: "[email protected]",
status: "active"
},
{
name: "Shoaib Akhtar",
age: 28,
email: "[email protected]",
status: "active"
}
]);
3. Read Query:
db.users.find();
OUTPUT:
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf6'),
name: 'Braham Kumar',
age: 25,
email: '[email protected]',
status: 'inactive'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
22
age: 35,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
name: 'Bikash Singh',
age: 28,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf9'),
name: 'Shoaib Akhtar',
age: 28,
email: '[email protected]',
status: 'active'
}
]
◉ Find documents with specific criteria (e.g., find all users with age greater
than 25):
OUTPUT:
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
age: 35,
email: '[email protected]',
status: 'active'
},
{
23
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
name: 'Bikash Singh',
age: 28,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf9'),
name: 'Shoaib Akhtar',
age: 28,
email: '[email protected]',
status: 'active'
}
]
4. Update Query:
◉ Update a single document:
db.users.updateOne(
{ name: "Bikash Singh" },
{ $set: { age: 31 } }
);
db.users.find({ age: { $gt: 31 } });
OUTPUT:
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
age: 35,
email: '[email protected]',
status: 'active'
24
}
]
db.users.updateMany(
{ age: { $gt: 28 } },
{ $set: { status: "inactive" } }
);
db.users.find({ age: { $gt: 28 } });
OUTPUT:
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
age: 35,
email: '[email protected]',
status: 'inactive'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
name: 'Bikash Singh',
age: 31,
email: '[email protected]',
status: 'inactive'
}
]
5. Delete Query:
◉ Delete a single document:
25
db.mycollection.deleteMany({ age: { $gt: 28 } });
5. Basic Queries:
db.users.count();
◉ Sorting documents:
db.users.find().limit(5);
◉ Aggregation queries (e.g., group by and aggregate functions):
db.users.aggregate([
{ $group: { _id: "$age", count: { $sum: 1 } } }
]);
26