DBMS LAB MANUAL-2022 Scheme
DBMS LAB MANUAL-2022 Scheme
PROGRAM 1
Solution:
insert into Employee values(1, 'Kavana Shetty', 'Manager', NULL, 50000.00, 1500.00);
mysql> COMMIT;
insert into Employee values(2, 'Shetty', 'Sales person', NULL, 5000.00, 500.00);
insert into Employee values(3, 'Karan', 'sales person', NULL, 5000.00, 1000.00);
mysql> ROLLBACK;
3. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result.
When we are trying to add null value to the column after adding NOT NULL
constraint.
PROGRAM 2
mysql> INSERT INTO Employee (EMPNO, ENAME, JOB, MGR, SAL, COMMISSION)
-> VALUES
PROGRAM 3
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
E_name VARCHAR(255),
Age INT,
FROM Employee
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)
NAME VARCHAR(255),
AGE INT,
ADDRESS VARCHAR(255),
---INSERT TRIGGER---
DELIMITER //
BEGIN
END;//
DELIMITER ;
---UPDATE TRIGGER---
DELIMITER //
BEGIN
END;//
DELIMITER ;
---DELETE TRIGGER---
DELIMITER //
BEGIN
END;//
DELIMITER ;
INSERT INTO CUSTOMERS VALUES (1,'Shankara', 35, '123 Main St', 50000.00);
UPDATE CUSTOMERS
WHERE ID = 1;
PROGRAM 5
Create cursor for Employee table & extract the values from the table. Declare the
variables, Open the cursor & extract the values from the cursor. Close the cursor.
CUSTOMERS(ID,NAME,AGE,ADDRESS,SALARY)
USE COMPANY05;
E_name VARCHAR(255),
Age INT,
DELIMITER //
BEGIN
SET @finished = 1;
OPEN emp_cursor;
SET @finished = 0;
cursor_loop: LOOP
IF @finished = 1 THEN
LEAVE cursor_loop;
END IF;
SELECT CONCAT('Employee ID: ', emp_id, ', Name: ', emp_name, ', Age: ', emp_age, ',
Salary: ', emp_salary) AS Employee_Info;
END LOOP;
CLOSE emp_cursor;
END//
DELIMITER ;
CALL fetch_employee_data();
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.
USE ROLLCALL;
student_name VARCHAR(255),
birth_date DATE);
student_name VARCHAR(255),
birth_date DATE);
DELIMITER //
BEGIN
FROM N_RollCall;
OPEN n_cursor;
cursor_loop: LOOP
IF done THEN
LEAVE cursor_loop;
END IF;
(SELECT 1
FROM O_RollCall
END IF;
END LOOP;
CLOSE n_cursor;
END//
DELIMITER ;
CALL merge_rollcall_data();
--Verify Records--
PROGRAM 7
Install an Open Source NoSQL Data base MongoDB & perform basic CRUD(Create, Read,
Update & Delete) operations. Execute MongoDB basic Queries using CRUD operations.
mongosh
5. INSERT operations
bookDB> db.ProgrammingBooks.insertMany([
year: 2008
},
category: "JavaScript",
year: 2008
},
year: 1994
},
category: "Algorithms",
year: 1990
},
category: "Python",
year: 2015
])
bookDB> db.ProgrammingBooks.find().pretty()
_id: ObjectId('663eaaebae582498972202df'),
year: 2008
},
_id: ObjectId('663eaaebae582498972202e0'),
category: 'JavaScript',
year: 2008
},
_id: ObjectId('663eaaebae582498972202e1'),
year: 1994
},
_id: ObjectId('663eaaebae582498972202e2'),
category: 'Algorithms',
year: 1990
},
_id: ObjectId('663eaaebae582498972202e3'),
category: 'Python',
year: 2015
},
_id: ObjectId('663eab05ae582498972202e4'),
year: 1999
_id: ObjectId('663eaaebae582498972202df'),
year: 2008
},
_id: ObjectId('663eaaebae582498972202e0'),
category: 'JavaScript',
year: 2008
},
_id: ObjectId('663eaaebae582498972202e3'),
category: 'Python',
year: 2015
7. Update Operations
bookDB>db.ProgrammingBooks.updateOne(
_id: ObjectId('663eaaebae582498972202df'),
year: 2008
},
_id: ObjectId('663eaaebae582498972202e0'),
category: 'JavaScript',
year: 2008
To update multiple books (e.g., update the category of books published before 2010):
bookDB> db.ProgrammingBooks.updateMany(
//verify the update operation by displaying books published before year 2010
_id: ObjectId('663eaaebae582498972202df'),
year: 2008
},
_id: ObjectId('663eaaebae582498972202e0'),
year: 2008
},
_id: ObjectId('663eaaebae582498972202e1'),
year: 1994
},
_id: ObjectId('663eaaebae582498972202e2'),
year: 1990
},
_id: ObjectId('663eab05ae582498972202e4'),
year: 1999
8. Delete Operations
To delete a specific book from the collection (e.g., delete a book by title):
To delete multiple books based on a condition (e.g., delete all books published before 1995):
To delete a collection named ProgrammingBooks, use the drop() method with the name of
the collection: