触发器被定义为存储的程序,每当发生 CREATE、ALTER、UPDATE、INSERT、DELETE 等事件时,它们就会自动执行。它们可以定义在与事件关联的数据库、表、视图上。
触发器可以大致分为行级触发器和语句级触发器。
从广义上讲,这些可以区分为:
Row Level Triggers | Statement Level Triggers |
---|---|
Row level triggers executes once for each and every row in the transaction. | Statement level triggers executes only once for each single transaction. |
Specifically used for data auditing purpose. | Used for enforcing all additional security on the transactions performed on the table. |
“FOR EACH ROW” clause is present in CREATE TRIGGER command. | “FOR EACH ROW” clause is omitted in CREATE TRIGGER command. |
Example: If 1500 rows are to be inserted into a table, the row level trigger would execute 1500 times. | Example: If 1500 rows are to be inserted into a table, the statement level trigger would execute only once. |