a need
When raising wages for employees, automatically back up the new work to the backup table.
two code
--触发器应用场景4:数据库的备份和同步
--当给员工涨工资,自动备份新的工资到备份表中
--创建备份表,
/*
create table emp_back as select * from emp;
*/
create or replace trigger sync_salay
after update
on emp
for each row
begin
--当主表更新后,自动更新备份表
update EMP_BACK set sal=:new.sal where empno =:new.empno;
end;
Three verification
SQL>select sal from emp where empno=7839;
SAL
----------
12101
SQL>select sal from emp_back where empno=7839;
SAL
----------
12101
SQL> update emp set sal=sal+10where empno=7839;
已更新1行。
SQL>select sal from emp where empno=7839;
SAL
----------
12111
SQL>select sal from emp_back where empno=7839;
SAL
----------
12111