DBMS Final Lab Manual
DBMS Final Lab Manual
IV SEMESTER
DATABASE MANAGEMENT SYSTEM LABORATORY LAB
MANUAL
[BCS403]
Compiled By:
VISION
To emerge as a centre for achieving academic excellence, by producing competent professionals
to meet the global challenges in the field of Information science and Technology.
MISSION
M1: To prepare the students as competent professionals to meet the advancements in the
industry and academia by imparting quality technical education.
M2: To enrich the technical ability of students to face the world with confidence, commitment,
and teamwork
.
M3: To inculcate and practice strong techno-ethical values to serve the society.
PEO3: To engage in research and development leading to new innovations and products.
PSO3: Demonstrate the knowledge towards the domain specific initiatives of Information
Science and Engineering.
Program Outcomes (POs):
Information Science and Engineering Graduates will be able to:
Course Outcomes:
At the end of the course, students will be able to
CO5 Apply the concepts of concurrency control and CRUD operations in NOSQL. L3
● Fundamentals of Database Systems, Ramez Elmasri and Shamkant B. Navathe, 7th Edition,
2017, Pearson.
● Database management systems, Ramakrishnan, and Gehrke, 3rd Edition, 2014, McGraw
Hill
REFERENCE BOOKS (RB):
● Abraham Silberschatz, Henry F. Korth and S. Sudarshan’s Database System Concepts 6th
EditionTata Mcgraw Hill Education Private Limited
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 subquestions), 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 scored by the student shall be proportionally scaled down to 50 Marks
Table of Contents
Program 1
2. Login to user account using username and password from command prompt
5. Insert the any three records in the employee table contains attributes EMPNO,
ENAME JOB, MANAGER_NO, SAL, COMMISSION and use rollback.
START TRANSACTION;
INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL,
COMMISSION) VALUES (1, 'John', 'Manager', 101, 50000, 1000);
INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL,
COMMISSION) VALUES (2, 'Alice', 'Developer', 101, 40000, 500);
INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL,
COMMISSION) VALUES (3, 'Bob', 'Analyst', 101, 35000, NULL);
ROLLBACK;
6. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result.
INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL,
COMMISSION) VALUES (4, 'Carol', NULL, 101, 45000, 700);
Output:
mysql> ROLLBACK;
Query OK, 0 rows affected (0.03 sec)
Program 2
Create a table called Employee that contain attributes EMPNO, ENAME, JOB, MGR, SAL
& execute the following.
1. Add a column commission with domain to the Employee table.
2. Insert any five records into the table.
3. Update the column details of job
4. Rename the column of Employ table using alter command.
5. Delete the employee whose Empno is 105.
Output:
Output:
UPDATE Employee
SET JOB = 'Lead Developer' WHERE ENAME = 'Alice';
Program 3
Queries using aggregate functions (COUNT, AVG, MIN, MAX, SUM), Group by, Orderby.
Employee (E_id, E_name, Age, Salary)
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
2. Count number of employee names from employee table
3. Find the Maximum age from employee table.
4. Find the Minimum age from employee table.
5. Find salaries of employee in Ascending Order.
6. Find grouped salaries of employees.
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
Program 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)
2. Create Trigger
DELIMITER //
DELIMITER ;
Program 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)
DELIMITER //
-- Declare a NOT FOUND handler to exit loop when there are no more rows
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET no_more_rows = TRUE;
-- Process the fetched values (you can perform any operations here)
-- For example, you can print the values
SELECT CONCAT('Employee ID: ', emp_id, ', Name: ', emp_name, ', Age: ', emp_age,
', Salary: ', emp_salary) AS output;
END LOOP;
DELIMITER ;
CALL fetch_employee_data();
Output:
mysql> CALL fetch_employee_data();
+-------------------------------------------------------+
| output |
+-------------------------------------------------------+
| Employee ID: 1, Name: John, Age: 30, Salary: 50000.00 |
+-------------------------------------------------------+
1 row in set (0.01 sec)
+--------------------------------------------------------+
| output |
+--------------------------------------------------------+
| Employee ID: 2, Name: Alice, Age: 28, Salary: 45000.00 |
+--------------------------------------------------------+
1 row in set (0.04 sec)
+------------------------------------------------------+
| output |
+------------------------------------------------------+
| Employee ID: 3, Name: Bob, Age: 35, Salary: 60000.00 |
+------------------------------------------------------+
1 row in set (0.06 sec)
+--------------------------------------------------------+
| output |
+--------------------------------------------------------+
| Employee ID: 4, Name: Carol, Age: 32, Salary: 55000.00 |
+--------------------------------------------------------+
1 row in set (0.10 sec)
+--------------------------------------------------------+
| output |
+--------------------------------------------------------+
| Employee ID: 5, Name: David, Age: 25, Salary: 40000.00 |
+--------------------------------------------------------+
1 row in set (0.12 sec)
Program 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.
Solution:
PL/SQL Code
DELIMITER $$
OPEN n_cursor;
fetch_loop: LOOP
IF done THEN
LEAVE fetch_loop;
END IF;
-- Diagnostic output
SELECT n_id, n_name, n_roll_no, n_present, v_id;
CLOSE n_cursor;
END$$
DELIMITER ;
OUTPUT:
mysql> CALL merge_data_from_n_to_o();
Query OK, 1 row affected (0.08 sec)
Program 7
Install an Open Source NoSQL Data base MangoDB & perform basic CRUD (Create, Read,
Update & Delete) operations. Execute MangoDB basic Queries using CRUD operations.
Data Types:
int
double
string
boolean
date
null
courses : [“Biology”,”Chemistry”,”Calculus”]
address:{Street:”123, 3rd main”, city:”Bengaluru”,zip:560074}
Basic Commands:
show dbs //show databases
use Employee //Create a database
db.createCollection(“students”) //create collections
db.students.insertMany([{usn:”1JS21IS002”,name:”AAC”,age:30,gpa:4.2},{
usn:”1JS21IS003”,name:”BAC”,age:30,gpa:2.2},
{usn:”1JS21IS004”,name:”BCA”,age:30,gpa:2.4}])
Sorting:
db.students.find().sort()
db.students.find().sort({name:1}) Alphabetical Order
db.students.find().sort({name:-1}) Reverse Order
db.students.find().limit(1)
db.students.find().sort({gpa:-1}).limit(1)
find():
db.students.find({name:”spongebob”})
db.students.find({name:”spongebob”},{name:true})
update():
db.students.updateOne({name:”spongebob”},{$set:{fullTime:true}})
db.students.updateOne({name:”spongebob”},{$unset:{fullTime:” ”}})
db.students.updateMany({ },{$set:{fullTime:false}})
db.students.updateMany({fullTime:{$exists:false}},{$set:{fullTime:true}})
delete():
db.students.deleteOne({name:”spongebob”})
db.students.deleteMany({fullTime:false})
db.students.deleteMany({registerDate:{$exists:false}})
Comparison Operators:
db.students.find({name:{$ne:”spongebob”}})
db.students.find({age:{$lt:20}})
db.students.find({gpa:{$gte:3,$lte:4}})
db.students.find({name:{$nin:[“pattrick”,”sandy”]}})
Logical Operators:
db.students.find({$and:[{fullTime:true},{age:{$lte:22}}]})
db.students.find({age:{$not:{$gte:30}}})
Drop Database:
db.courses.drop()