Home     DB      Replicator      CRM      Solutions  

License Policy
One$ DB FAQ
Pricing Policy
Support Overview
Features
Documentation
Compatible Products
Data Migration
Features Comparison
Performance Comparison
Daffodil DB
User Guide > Features > Comprehensive Triggers > Before and After Triggers
 
Before and After Triggers


When defining a trigger, you can specify the trigger timing as whether the trigger action is to be executed before or after the triggering statement. BEFORE and AFTER apply to both statement and row triggers.

Before Triggers

As the name suggests, before triggers are fired before the execution of a triggering statement. For example a before trigger can be used to take back up of data contained in a table before a particular batch of statements.

Before triggers are combined with DML statements (Insert /Update/Delete) to construct the triggering condition for a table. For example, the following query updates a table called audit before any changes/ insertions are made to the school table.

create trigger Trigger_Name
before insert on teacher
referencing old row as oldRow
for each row update audit set salary=salary+8000

BEFORE triggers execute the trigger action before the triggering statement is executed. This type of trigger is commonly used in the following situations:

  • When the trigger action should determine whether the triggering statement should be allowed to execute.
  • To eliminate unnecessary processing of the triggering statement and its eventual rollback in cases where an exception is raised in the trigger action.
  • To derive specific column values before completing a triggering INSERT or UPDATE statement.

After Triggers

AFTER triggers execute the trigger action after the triggering statement is executed. AFTER triggers are used in the following situations:

  • When you want the triggering statement to complete before executing the trigger action.
  • If a BEFORE trigger is already present, an AFTER trigger can perform different actions on the same triggering statement.

The following examples depict the usage and syntax for triggers in Daffodil DB.

You can create a trigger on the Daffodil DB sample database table with the help of following statement:

create trigger sample_trigger
before delete on student
referencing old row as oldRow
for each row update student set age=age+1

You can delete an existing trigger on the Daffodil DB sample database table with the help of the following statement.

drop trigger sample_trigger

For more information and support regarding any issue related to Daffodil DB Contact us at support@daffodildb.com

 

 
Web Database | SQL Database | Embedded Database
©2006 Daffodil Software Ltd. Contact Us | Disclaimer | Sitemap