Firebird incorporates some features that can be implemented in database design to respond to DML operations that change the state of data, namely the posting of INSERT, UPDATE, and DELETE statements.
Referential Integrity Action Clauses
Referential integrity triggers are modules of compiled code created by the engine when you define referential integrity constraints for your tables. By including ON UPDATE and ON DELETE action clauses in FOREIGN KEY constraint declarations, you can specify one of a selection of pre-defined response actions that will occur when these DML events execute.
With custom triggers (those you write yourself using the PSQL language), you have the capability to specify exactly what is to happen when the server receives a request to insert, change, or delete rows in tables. Custom triggers can be applied not just to the update and delete events, but also to inserts. Triggers can include exception handling, feedback, and (in Firebird 1.5) custom query plans.
DML Event Phases
Trigger syntax splits the custom DML actions into two phases: the first phase occurs before the event, and the second occurs after the event.
Table describes the six phases/events of custom triggers.
The Six Phases/Events of Custom Triggers
NEW and OLD Context Variables
The server makes two sets of context variables available to triggers. One consists of all the field values of the current row, as they were in the current row just before the row was last posted. The identifiers for this set consist of the word “OLD.” prefixed to each column identifier. In the same manner, all of the new values have “NEW.” prefixed to each column identifier. Of course, “OLD.” is meaningless in an insert trigger and “NEW.” is meaningless in a delete trigger.
From Firebird 1.5 onward, you can optionally write triggers with conditioned logic to roll all of the events (insert, update, and delete) for one phase—BEFORE or AFTER— into one trigger module. This is a long-awaited enhancement that can save up to two-thirds of the coding of triggers.
Multiple Triggers per Event
Another useful option is the ability to have multiple triggers for each phase/event combination. CREATE TRIGGER syntax includes the keyword POSITION, taking an integer argument that can be used to set the zero-based firing order of multiple triggers within a phase.
Firebird Related Interview Questions
|RDBMS Interview Questions||MySQL Interview Questions|
|Linux Interview Questions||Mac OS X Deployment Interview Questions|
|Windows Administration Interview Questions||Windows Server 2003 Interview Questions|
|SQL Interview Questions||NoSQL Interview Questions|
|Advanced C++ Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.