0% found this document useful (0 votes)
16 views

Triggers

A trigger is a named program unit stored in a database that fires in response to a specified event, such as a data manipulation language (DML) statement like INSERT or DELETE. There are different types of triggers including DML triggers that fire on DML statements, and INSTEAD OF triggers defined on views. Triggers can fire at different timing points either before or after the triggering statement executes or each affected row. Triggers exist in either an enabled or disabled state to control whether the trigger executes its body in response to the triggering event.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Triggers

A trigger is a named program unit stored in a database that fires in response to a specified event, such as a data manipulation language (DML) statement like INSERT or DELETE. There are different types of triggers including DML triggers that fire on DML statements, and INSTEAD OF triggers defined on views. Triggers can fire at different timing points either before or after the triggering statement executes or each affected row. Triggers exist in either an enabled or disabled state to control whether the trigger executes its body in response to the triggering event.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

TRIGGERS

A trigger is a named program unit that is stored in the database and fired
(executed) in response to a specified event. The specified event is associated
with a table, a view, a schema, or the database, and it is one of the following:

• A database manipulation (DML) statement (DELETE, INSERT, or


UPDATE)
• A database definition (DDL) statement (CREATE, ALTER, or DROP)
• A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP,
or SHUTDOWN).

Trigger Types

A DML trigger is fired by a DML statement, a DDL trigger is fired by a


DDL statement, a DELETE trigger is fired by a DELETE statement, and so
on.

An INSTEAD OF trigger is a DML trigger that is defined on a view (not a


table).

A system trigger is defined on a schema or the database. A trigger defined


on a schema fires for each event associated with the owner of the schema
(the current user). A trigger defined on a database fires for each event
associated with all users.

A simple trigger can fire at exactly one of the following timing points:

• Before the triggering statement executes


• After the triggering statement executes
• Before each row that the triggering statement affects
• After each row that the triggering statement affects

A compound trigger can fire at more than one timing point. Compound
triggers make it easier to program an approach where you want the actions
you implement for the various timing points to share common data.
Trigger States

A trigger can be in either of two states:

Enabled: An enabled trigger executes its trigger body if a triggering


statement is entered and the trigger restriction (if any) evaluates to TRUE.

Disabled: A disabled trigger does not execute its trigger body, even if a
triggering statement is entered and the trigger restriction (if any) evaluates to
TRUE.

By default, a trigger is created in enabled state. To create a trigger in


disabled state, use the DISABLE clause of the CREATE TRIGGER
statement.

You might also like