Tuesday 12 June 2018

DML Trigger

DML triggers are the triggers which are created over DML statements such as insert into a table, update a view, delete from a table etc. DML triggers execute every time a DML statement is executed.
Mainly DML triggers are 2 types, row level and statement level.

Row level triggers are fired whenever a row changes (Row Level trigger will always fire for each row) .
Statement level triggers are fires whenever any statement executes ( for example a batch update like I am updating the whole table using just one update command, the trigger will fire only once ) . Both row level and statement level can be defined with 3 different DMLs, insert,delete and update.

Row Level and Statement Level Trigger:

  • Before Insert  and After Insert 
  • Before Update and After Update
  • Before Delete and After Delete

CREATE  TABLE schema_audit
 (
  ddl_date      DATE,
  ddl_user      VARCHAR2(15),
  object_created    VARCHAR2(15),
  object_name     VARCHAR2(15),
  ddl_operation    VARCHAR2(15)
);

ALTER TRIGGER:

Alter Trigger command can be used to rename, compile, disable and enable the trigger.

Recompile Trigger:
ALTER TRIGGER trigger_name compile;

Disable Trigger:


ALTER TRIGGER trigger_name disable;

Enable Trigger:


ALTER TRIGGER trigger_name enable;

Rename Trigger:


ALTER TRIGGER trigger_name_old rename to trigger_name_new;



No comments:

Post a Comment