Database Trigger

Database Trigger

« Back to Glossary Index
Visit Us
Follow Me

A database trigger is a procedural code that is automatically executed or fired in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

For example, a trigger can restrict access to specific data, perform logging, or audit data modifications. It can enforce business rules, derive computed column values, and streamline complex multi-table updates.

Triggers in a database are invoked by the occurrence of the following events:

  1. Data Manipulation Language (DML) Triggers: These triggers are invoked when a data manipulation language (DML) event takes place. DML events are INSERT, UPDATE, or DELETE statements on a table or view.
  2. Data Definition Language (DDL) Triggers: These triggers are invoked when a data definition language (DDL) event takes place. DDL events are CREATE, ALTER, or DROP statements.
  3. Logon Triggers: These triggers are invoked when a LOGON event takes place, often used to control server session settings.

Triggers can be defined to execute either before or after the triggering event. For instance, you can have a trigger that will be executed before an INSERT operation is executed on a table or after the operation is performed.

Note that while triggers can be very useful, they can also be potentially harmful if not implemented properly. For instance, triggers can cause unwanted side-effects, create recursive loops, or cause performance problems if they perform heavy processing or contain inefficient queries. Thus, it is important to use triggers judiciously and monitor their effects on your database system.

You may also like...