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 the and/or usage:

    That he is old, the more the pity, his white hairs do witness it.
    William Shakespeare (1564–1616)

    I am using it [the word ‘perceive’] here in such a way that to say of an object that it is perceived does not entail saying that it exists in any sense at all. And this is a perfectly correct and familiar usage of the word.
    —A.J. (Alfred Jules)