0% found this document useful (0 votes)
2 views2 pages

Unit 4 PL SQL A58

The document contains SQL trigger definitions for managing employee records in a database. It includes triggers for deleting, updating, and inserting employee data, as well as specific actions based on department conditions. Each trigger logs changes or inserts data into separate tables for auditing purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Unit 4 PL SQL A58

The document contains SQL trigger definitions for managing employee records in a database. It includes triggers for deleting, updating, and inserting employee data, as well as specific actions based on department conditions. Each trigger logs changes or inserts data into separate tables for auditing purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1)

create or replace trigger EMPDELTRG


before delete on emps
for each row
begin
insert into EMPDELS values(:old.eno, :old.ename, :old.dep, :old.sal, sysdate);
end;
/

delete from emps where eno=5;

-------------------

2)
create or replace trigger updatingtrg
before update on emps
for each row
declare
dsal int;
begin
dsal:=:new.sal-:old.sal;
dbms_output.put_line('Difference:- '||dsal);
end;
/

update emps set sal=25000 where eno=1;

-------------------

3)
create or replace trigger EMPINSTRG
before insert on emps
for each row
begin
insert into EMPINS values(:new.eno, :new.dep, :new.sal);
end;
/

insert into emps values(7, 'Dhruve', 'Finance', 50000);

select * from EMPINS;

-------------------

4)
CREATE OR REPLACE TRIGGER ittrigger
AFTER INSERT ON emps
FOR EACH ROW
BEGIN
IF (:new.dep = 'IT') THEN
INSERT INTO it_table VALUES (:new.eno, :new.ename, :new.dep, :new.sal);
END IF;
END;
/

-------------------

5)
create or replace trigger upsaltrg
before update on emps
for each row
begin
insert into new_emp values(:old.eno, :old.sal, :new.sal);
end;
/

update emps set sal=20000 where eno=2;

select * from new_emp;

You might also like