Feb
16
2012

What is a Database Trigger?

A database trigger is a form of stored procedure which is immediately processed in response to certain events with a database.  A database trigger may allow the user to block any transactions, perform logging as well as modifying data within the database.  Trigger can be classified into two types – the “row” triggers and the “statement” triggers.  “Row” triggers usually occur for every row of a specific table, while “statement” triggers can only be executed once in every INSERT (a new record or input is being placed in the database), UPDATE (a record is being changed) and DELETE (a record is being removed) statement.  Keep in mind that triggers cannot be executed in the SELECT statement.

Other types of triggers include “BEFORE” and “AFTER” triggers.  “BEFORE” triggers usually performs the triggering action before the triggering statement.  On the other hand, “AFTER” triggers are usually performed after the triggering statement.

When using database triggers, a user must consider these following effects:

1.         Data triggers don’t accept argument, but they temporarily store affected data in specific tables.

2.         Data triggers cannot work on rollback operations because they are a part of an SQL server.  Triggers can only be done autonomously.

If data triggers are not properly written, triggers may develop and receive erroneous data.

What is a Database Trigger? database trigger

How to Utilize Database Triggers

 

Database triggers are used to have a highly-modified database management system.  For instance, users can organize their weekly files by only using several commands or triggers.  Other uses of database triggers include security of important files.  Database triggers automatically produce derived column values.  It also checks invalid transactions, implement security authorization as well as integrity among users.  Moreover, database triggers allow transparency in logging, complexity in auditing, integration in table replication as well as implementation of business rules plus accessibility of data from data tables.

Components of a Database Trigger

 

To better understand the function of a database trigger, you need to learn about the components of a database trigger.

The first part is the triggering statement or event.  The triggering statement or event is an SQL code that executes a trigger to be activated.  A triggering statement may indicate an UPDATE, an INSERT or a DELETE procedure.  The second part is the trigger restriction.  The trigger restriction refers to a logical or Boolean expression.  This expression should be TRUE so that the trigger will be implemented.  The trigger will not be executed if the expression is incorrect or FALSE.  Trigger restriction is an alternative procedure available in each row of the table.  Trigger restriction works by monitoring the procedure made in each table.  Just use the WHEN clause during the execution of the trigger restriction.  The last part of the database trigger is the trigger action.  The trigger action is executed when the triggering statement is employed and the expression is TRUE.  Just like the stored procedure, the trigger action contains the SQL statement and the PL/SQL code.

In using the database trigger, you need to specify the statement as well as the validity of the expression.



Comments are closed.

Advertisements