DBMS_Lab_program
DBMS_Lab_program
Employee(EMPNO,ENAME,JOB,
MANAGER_NO, SAL, COMMISSION)
2. Insert the any three records in the employee table contains attributes EMPNO,ENAME JOB,
MANAGER_NO, SAL, COMMISSION and use rollback. Check the result.
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.
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.
UPDATE Employee
SET JOB = 'Senior Developer'
WHERE EMPNO = 102;
USE COMPANY03;
CREATE TABLE Employee ( E_id INT PRIMARY KEY, E_name VARCHAR(255), Age INT, Salary
DECIMAL(10, 2) );
FROM Employee
FROM Employee
GROUP BY Salary;
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)
CREATE DATABASE COMPANY04;
USE COMPANY04;
CREATE TABLE CUSTOMERS ( ID INT PRIMARY KEY, NAME VARCHAR(255),
AGE INT, ADDRESS VARCHAR(255), SALARY DECIMAL(10, 2) );
-- INSERT TRIGGER
DELIMITER //
CREATE TRIGGER after_insert
AFTER INSERT ON CUSTOMERS
FOR EACH ROW
BEGIN
SET @ins_sal = CONCAT('Inserted salary is ', NEW.SALARY);
END; //
DELIMITER ;
-- UPDATE TRIGGER
CREATE TRIGGER after_update
AFTER UPDATE ON CUSTOMERS
FOR EACH ROW
BEGIN
SET @upd_sal = CONCAT('After updating salary difference is ', NEW.SALARY -
OLD.SALARY);
END;
-- DELETE TRIGGER
CREATE TRIGGER after_delete
AFTER DELETE ON CUSTOMERS
FOR EACH ROW
BEGIN
SET @del_sal = CONCAT('Deleted salary is ', OLD.SALARY);
END;
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)
Password : root123
USE COMPANY05;
VALUES (1, 'Samarth', 30, 50000.00), (2, 'Ramesh Kumar', 25, 45000.00),
(3, 'Seema Banu', 35, 62000.00), (4, 'Dennis Anil', 28, 52000.00),
DELIMITER //
BEGIN
-- Declare variables to store cursor values
FROM Employee;
SET @finished = 1;
OPEN emp_cursor;
SET @finished = 0;
cursor_loop: LOOP
IF @finished = 1 THEN
LEAVE cursor_loop;
END IF;
END LOOP;
CLOSE emp_cursor;
END//
delimiter ;
CALL fetch_employee_data();
Output:
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 ROLLCALL1;
CREATE TABLE N_RollCall ( stud_id INT PRIMARY KEY, stud_name VARCHAR(55), b_date DATE);
INSERT INTO O_RollCall (stud_id, stud_name, b_date) VALUES (1, 'Shiva', '1995-08-15'),
--DELIMITER //: changes the default SQL delimiter ";" to "//" so that MySQL does not mistakenly
execute the procedure before it is fully written.
BEGIN
DECLARE id INT;
OPEN stud_cursor;
cursor_loop: LOOP
END IF;
END IF;
END LOOP;
CLOSE stud_cursor;
END//
DELIMITER ;
CALL merge_rollcall_data();
2. Open the Command Prompt and type the command “mongosh” to switch to the MongoDB
Shell
use MyMongoDB
db.createCollection("orders”)
MongoDB doesn't use the rows and columns. It stores the data in a document format. A collection is
a group of documents
use bookDB
db.createCollection("ProgrammingBooks")
db.ProgrammingBooks.insertMany([
year: 2008
},
category: "JavaScript",
year: 2008
},
year: 1994
},
category: "Algorithms",
year: 1990
},
category: "Python",
year: 2015
])
db.ProgrammingBooks.find().pretty()
db.ProgrammingBooks.insertOne({
year: 1999
})
db.ProgrammingBooks.find().pretty()
db.ProgrammingBooks.updateOne(
db.ProgrammingBooks.updateMany(
db.ProgrammingBooks.deleteMany({})
//delete collection
db.ProgrammingBooks.drop()