Database Trigger - The Need and The Usage

The Need and The Usage

Triggers are commonly used to:

  • audit changes (e.g. keep a log of the users and roles involved in changes)
  • enhance changes (e.g. ensure that every change to a record is time-stamped by the server's clock)
  • enforce business rules (e.g. require that every invoice have at least one line item)
  • execute business rules (e.g. notify a manager every time an employee's bank account number changes)
  • replicate data (e.g. store a record of every change, to be shipped to another database later)
  • enhance performance (e.g. update the account balance after every detail transaction, for faster queries)

The examples above are called Data Manipulation Language (DML) triggers because the triggers are defined as part of the Data Manipulation Language and are executed at the time the data is manipulated. Some systems also support non-data triggers, which fire in response to Data Definition Language (DDL) events such as creating tables, or runtime or and events such as logon, commit and rollback. Such DDL triggers can be used for database auditing purposes.

The following are major features of database triggers and their effects:

  • triggers do not accept parameters or arguments (but may store affected-data in temporary tables)
  • triggers cannot perform commit or rollback operations because they are part of the triggering SQL statement (only through autonomous transactions)
  • triggers are normally slow (slowdown the process)

Read more about this topic:  Database Trigger

Famous quotes containing the words usage and/or the:

    ...Often the accurate answer to a usage question begins, “It depends.” And what it depends on most often is where you are, who you are, who your listeners or readers are, and what your purpose in speaking or writing is.
    Kenneth G. Wilson (b. 1923)

    The New Testament is remarkable for its pure morality; the best of the Hindoo Scripture, for its pure intellectuality. The reader is nowhere raised into and sustained in a higher, purer, or rarer region of thought than in the Bhagvat-Geeta.... It is unquestionably one of the noblest and most sacred scriptures which have come down to us.
    Henry David Thoreau (1817–1862)