Database trigger

Triggers can also be used to log historical data, for example to keep track of employees' previous salaries.

In addition to triggers that fire (and execute PL/SQL code) when data is modified, Oracle 10g supports triggers that fire when schema-level objects (that is, tables) are modified and when user logon or logoff events occur.

The following functionality in SQL:2003 was previously not implemented in PostgreSQL: Synopsis: Firebird supports multiple row-level, BEFORE or AFTER, INSERT, UPDATE, DELETE (or any combination of thereof) triggers per table, where they are always "in addition to" the default table changes, and the order of the triggers relative to each other can be specified where it would otherwise be ambiguous (POSITION clause.)

(Before version 2.1, triggers on views deemed updatable would run in addition to the default logic.)

If exception is thrown from before trigger then operation is aborted and no data are changed.

Triggers in Sedna were designed to be analogous to SQL:2003 triggers, but natively base on XML query and update languages (XPath, XQuery and XML update language).

A trigger in Sedna is set on any nodes of an XML document stored in database.

Here it is important to note that even if the UPDATE command didn't affect any rows, the code within the trigger will still be executed once.

When the trigger is called it adds an entry into a separate table named phone_book_audit.

Also take note of triggers being able to take advantage of schema objects like sequences,[8] in this example audit_id_sequence.nexVal is used to generate unique primary keys in the phone_book_audit table.

Since the update modified two separate row values, the created trigger was called twice; once after each modification.

An Oracle syntax statement trigger that is called after an UPDATE to the phone_book table.

This example demonstrates a BEFORE EACH ROW trigger that modifies the INSERT using a WHEN conditional.

If the last name is larger than 10 letters, using the SUBSTR function[9] we change the last_name column value to an abbreviation.

The trigger worked as per the result above, modifying the value of the INSERT before it was executed.

[10] This example demonstrate how to enforce a restriction upon someone named "SOMEUSER" on the table phone_book.