DBMS lab
DBMS lab
-- Check that the records were rolled back (should return 0 rows)
SELECT * FROM Employee;
Step 4: Add primary key constraint and not null constraint:
Alter table to add primary key constraint on EMPNO
ALTER TABLE Employee
ADD CONSTRAINT pk_employee PRIMARY KEY (EMPNO);
-- This insert will fail due to the NOT NULL constraint on ENAME
Create Employee table containing all Records E_id, E_name, Age, Salary.
Count number of employee names from employee table.
Find the Maximum age from employee table.
Find the Minimum age from employee table.
Find salaries of employee in Ascending Order.
Find grouped salaries of employees.
NAME VARCHAR2(100),
AGE NUMBER,
ADDRESS VARCHAR2(200),
SALARY NUMBE );
ON CUSTOMERS
DECLARE
v_old_salary CUSTOMERS.SALARY%TYPE;
v_new_salary CUSTOMERS.SALARY%TYPE;
v_salary_diff CUSTOMERS.SALARY%TYPE;
BEGIN
IF INSERTING THEN
v_old_salary := 0;
v_new_salary := :NEW.SALARY;
v_old_salary := :OLD.SALARY;
v_new_salary := :NEW.SALARY;
v_old_salary := :OLD.SALARY;
v_new_salary := 0;
END IF;
END;
Step 3: Test the Trigger: Now, perform INSERT, UPDATE, and DELETE
operations on the CUSTOMERS table to see the trigger in action.
i) Insert Operation:
UPDATE CUSTOMERS
WHERE ID = 1;
WHERE ID = 1;
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. Employee (E_id, E_name, Age, Salary).
CURSOR employee_cursor IS
SELECT E_id, E_name, Age, Salary FROM Employee;
BEGIN
OPEN employee_cursor;
LOOP
FETCH employee_cursor INTO v_E_id, v_E_name, v_Age, v_Salary;
EXIT WHEN employee_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('E_id: ' || v_E_id || ', E_name: ' || v_E_name || ',
Age: ' || v_Age || ', Salary: ' || v_Salary);
END LOOP;
CLOSE employee_cursor;
END;
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.
id NUMBER,
name VARCHAR2(100),
roll_date DATE );
CURSOR c_merge_rollcall_data IS
SELECT id, name, roll_date
FROM N_RollCall nrc
WHERE NOT EXISTS (
SELECT 1
FROM O_RollCall orc
WHERE orc.id = nrc.id
AND orc.name = nrc.name
AND orc.roll_date = nrc.roll_date
);
BEGIN
OPEN c_merge_rollcall_data;
LOOP
FETCH c_merge_rollcall_data INTO v_n_rollcall_id, v_n_rollcall_name,
v_n_rollcall_date;
EXIT WHEN c_merge_rollcall_data%NOTFOUND;
db.users.insertMany([
{
name: "Braham Kumar",
age: 25,
email: "[email protected]",
status: "inactive"
},
{
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"
}
]);
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf6'),
name: 'Braham Kumar',
age: 25,
email: '[email protected]',
status: 'inactive'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
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'
}
]