DBMS Lab Manual
DBMS Lab Manual
2. Insert the any three records in the employee table contains attributes
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.
STEP-1 :
==Grant all privileges to the user (basic privileges like create, alter, delete, etc.)==
GRANT ALL PRIVILEGES ON DB_name.* TO 'new_user'@'localhost';
==Optionally, you may also grant the user the ability to create tables, views, and other objects==
STEP-2 :
START TRANSACTION;
INSERT INTO employee1 VALUES (1001, 'John Doe', 'Manager', NULL, 50000, 1000);
INSERT INTO employee1 VALUES (1002, 'Jane Smith', 'Clerk', 1001, 30000, 500);
INSERT INTO employee1 VALUES (1003, 'Sam Brown', 'Analyst', 1001, 45000, 700);
NOW ROLLBACK :
ROLLBACK;
YOU WILL OBSERVE THAT EMPLOYEE TABLE HAS EMPTY SET.
STEP-3 :
STEP-4 :
INSERT INTO employee1 VALUES (1004, NULL, 'Manager', NULL, 55000, 1000);
----------------------------------------------------------------------------
EXPERIMENT-2
Create a table called Employee that contain attributes EMPNO, ENAME, JOB, MGR, SAL
& execute the following.
3. UPDATE Employee1
+-------+---------------+----------------+------------+------+------------+
+-------+---------------+----------------+------------+------+------------+
+-------+---------------+----------------+------------+------+------------+
------------------------------------------------------------------------------------
EXPERIMENT-3
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
emp_name VARCHAR(100),
Age INT,
Salary DECIMAL(10, 2)
);
FROM Employee;
4.SELECT MIN(Age) AS Min_Age
FROM Employee;
FROM Employee
FROM Employee
GROUP BY Salary
ORDER BY Salary;
FROM Employee
GROUP BY Salary
----------------------------------------------------------------------------------------------------
EXPERIMENT-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).
operation VARCHAR(10),
customer_id INT,
salary_difference INT,
);
DELIMITER $$
BEGIN
END $$
DELIMITER ;
DELIMITER $$
BEGIN
END IF;
END $$
DELIMITER ;
6.CREATE DELETE TRIGGER :
DELIMITER $$
BEGIN
END $$
DELIMITER ;
INSERT INTO customers (ID, name, age, address, salary) VALUES (6, 'David', 28, 'Kerala', 45000);
------------------------------------------------------------------------------------------------
EXPERIMENT-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
E_name VARCHAR(50),
Age INT,
Salary DECIMAL(10, 2)
);
DELIMITER $$
CREATE PROCEDURE fetch_employee_details()
BEGIN
-- Declare a handler to set 'done' to TRUE when no more rows are found
OPEN employee_cursor;
read_loop: LOOP
LEAVE read_loop;
END IF;
-- Process the values (e.g., print them using SELECT or insert into another table)
END LOOP;
CLOSE employee_cursor;
END $$
DELIMITER ;
CALL fetch_employee_details();
--------------------------------------------------------------------------------------------------
EXPERIMENT-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.
STEP-1 :
attendance_date DATE,
);
VALUES
STEP-2 :
attendance_date DATE,
);
-> VALUES
STEP-3 :
DELIMITER $$
BEGIN
FROM N_RollCall;
OPEN cur;
read_loop: LOOP
-- Fetch the data from the cursor into the local variables
IF done THEN
LEAVE read_loop;
END IF;
-- Check if the record already exists in O_RollCall
IF NOT EXISTS (
SELECT 1
FROM O_RollCall
WHERE id = v_roll_call_id
) THEN
END IF;
END LOOP;
CLOSE cur;
COMMIT;
END $$
DELIMITER ;
STEP-4 :
CALL THAT PROCEDURE
CALL Merge_RollCall_Data();
+--------------+------------+-----------------+
+--------------+------------+-----------------+
| 1| 1001 | 2025-04-01 |
| 2| 1002 | 2025-04-02 |
| 3| 1003 | 2025-04-01 |
| 4| 1004 | 2025-04-01 |
| 5| 1005 | 2025-04-01 |
| 6| 1006 | 2025-04-01 |
+--------------+------------+-----------------+
+--------------+------------+-----------------+
+--------------+------------+-----------------+
| 1| 1001 | 2025-04-01 |
| 2| 1002 | 2025-04-01 |
| 3| 1003 | 2025-04-01 |
| 4| 1004 | 2025-04-01 |
| 5| 1005 | 2025-04-01 |
+--------------+------------+-----------------+
------------------------------------------------------------------------------------------
EXPERIMENT-7
Install an Open Source NoSQL Data base MangoDB & perform basic
https://www.mongodb.com/try/download/community
2.COPY THE MONGODB SERVER PATH AND PASTE IT IN THE ENVIRONMENT VARIABLES
GIVE THIS COMMAND : net start MongoDB(IT STARTS THE SERVER FOR MONGODB)
KEEP OPEN THE COMMAND PROMPT WINDOW TILL YOU FINISHED YOUR WORK IN MONGO
COMPASS(DON'T CLOSE)
6.AFTER CONNECTED TO THE SERVER CLICK ON CREATE DATABSE AND CREATE YOUR OWN DATABASE
AND ADD THE COLLECTION NAME THEIR ITSELF.
TO DO THE OPERATIONS FIRST WE HAVE TO USE THAT DATABASE WHICH WE HAVE CREATED :
STEP-2 : If you want to create collections in the database use this query
IN EASTPOINT DATABASE :
INPUT - >db.createCollection("users")
OUTPUT - <{ ok: 1 }
If you are not created any database as per the 6th point and try to do the 2nd step then it will
create "test" database automatically and uses the same.
IN TEST DATABSE :
INPUT - >db.createCollection("EPCET")
db.users.insertOne({
age: 30,
email: "[email protected]"
})
This command inserts a document with name, age, and email fields into the users collection.
])
db.users.find()
Find documents with a specific condition (e.g., age greater than 30):
{ $set: { age: 31 } }
db.users.updateMany(
{ age: { $gt: 30 } },
This adds a status field with value "senior" to all users with an age greater than 30.
db.users.drop()
show dbs
show collections
STEP-4: Exit MongoDB Shell(If you are using terminal not in compass)
exit
Drop: drop()
These are some of the key query operators you can use in MongoDB to match documents based on
different conditions: