I have two tables emp & copy_emp with same structure and same datas.
I want if any changes occurred in emp should be reflect in copy_emp.
Hence i created a trigger which i gave below.
create or replace trigger t
after
insert or
update of empno or
delete
on emp
for each row
begin
case
when inserting then
insert into copy_emp(empno,ename,sal) values (:NEW.empno,:NEW.ename,:NEW.sal);
when updating then
if updating('empno') then
update copy_emp set copy_emp.empno=:new.empno where copy_emp.empno=:old.empno;
elsif updating('ename') then
update copy_emp set copy_emp.ename=:new.ename where copy_emp.ename=:old.ename;
elsif updating('sal') then
update copy_emp set copy_emp.sal=:new.sal where copy_emp.sal=:old.sal;
end if;
when deleting then
delete from copy_emp where empno = :old.empno;
end case;
end;
Trigger got created without any errors and inserting and deleting work fine.
problem is with updating. when i update empno column in emp table, it also get updated in copy_emp table. but when i update ename or sal column it only get updated in emp table but not in copy_emp table. Please help.