數據庫觸發器是一個與表相關聯的,存儲的PL/SQL 語句。每當一個特定的數據操做語句(insert update delete)在指定的表上發出時,Oracle自動執行觸發器中定義的語句序列。sql
觸發器的應用場景以下:數據庫
CREATE [OR REPLACE] TRIGGER trigger_name {BEFORE | AFTER } {INSERT | DELETE | UPDATE [OF column [, column …]]} [OR {INSERT | DELETE | UPDATE [OF column [, column …]]}...] ON [schema.]table_name | [schema.]view_name [REFERENCING {OLD [AS] old | NEW [AS] new| PARENT as parent}] [FOR EACH ROW ] [WHEN condition] PL/SQL_BLOCK | CALL procedure_name;
其中:安全
create or replace trigger sync_salary after update on emp for each row begin --當主表更新後,自動更新備份表。 update emp_back set sal=:new.sal where empno=:new.empno; end; /