Pages

PL/SQL Triggers

Triggers are named PL/SQL blocks which are stored in the database or we can also say that they are specialized stored programs which execute implicitly when a triggering event occurs which means we cannot call and execute them directly instead they only get triggered by events in the database.


Events Which Fires the Triggers:

These events can be anything such as

  • A DML Statement. For example Update, Insert or Delete, executing on any table of your database. You can program your trigger to execute either BEFORE or AFTER executing your DML statement. For example you can create a trigger which will get fired Before the Update statement. Or you can create a trigger which will get triggered after the execution of your INSERT DML statement.
  • Next type of triggering statement can be a DDL Statement such as CREATE or ALTER. These triggers can also be executed either BEFORE or AFTER the execution of your DDL statement. These triggers are generally used by DBAs for auditing purposes and they really come in handy when you want to keep an eye on the various changes on your schema such as who created the object or which user. Just like some cool spy tricks.
  • A system event. Yes, you can create a trigger on a system event and by system event I mean shut down or startup of your database.
  • Another type of triggering event can be User Events such as log off or log on onto your database. You can create a trigger which will either execute before or after the event and record the information such as time of event occur, the username who created it.

No comments:

Post a Comment

Featured post

Snowflake - Creating warehouse in Snowflake

Creating warehouse Login to Snowflake and click on warehouse and click on Create fill the necessary details and click Finish We can also c...