# EVIDENCE-OF: R-51478-11146 A trigger may be specified to fire whenever
# a DELETE, INSERT, or UPDATE of a particular database table occurs, or
# whenever an UPDATE occurs on on one or more specified columns of a
# table.

FOR EACH ROW implies that the SQL statements specified in the trigger
may be executed (depending on the WHEN clause) for each database row being
inserted, updated or deleted by the statement causing the trigger to fire.

/* IMP: R-32235-53300 */

# EVIDENCE-OF: R-32235-53300 FOR EACH ROW implies that the SQL
# statements specified in the trigger may be executed (depending on the
# WHEN clause) for each database row being inserted, updated or deleted
# by the statement causing the trigger to fire.

Both the WHEN clause and the trigger actions may access elements of
the row being inserted, deleted or updated using references of the form
"NEW.column-name" and "OLD.column-name", where
column-name is the name of a column from the table that the trigger
is associated with.

/* IMP: R-25950-00887 */

# EVIDENCE-OF: R-25950-00887 Both the WHEN clause and the trigger
# actions may access elements of the row being inserted, deleted or
# updated using references of the form "NEW.column-name" and
# "OLD.column-name", where column-name is the name of a column from the
# table that the trigger is associated with.

# EVIDENCE-OF: R-63660-13730 OLD and NEW references may only be used in
# triggers on events for which they are relevant, as follows: INSERT NEW
# references are valid UPDATE NEW and OLD references are valid DELETE
# OLD references are valid

However if an ON CONFLICT clause is specified as part of
the statement causing the trigger to fire, then conflict handling
policy of the outer statement is used instead.

/* IMP: R-35856-58769 */

# EVIDENCE-OF: R-35856-58769 However if an ON CONFLICT clause is
# specified as part of the statement causing the trigger to fire, then
# conflict handling policy of the outer statement is used instead.

The name of the table to be modified in an UPDATE, DELETE, or INSERT
statement must be an unqualified table name. In other words, one must
use just "tablename" not "database.tablename"
when specifying the table.

/* IMP: R-42881-44982 */

# EVIDENCE-OF: R-42881-44982 The name of the table to be modified in an
# UPDATE, DELETE, or INSERT statement must be an unqualified table name.
# In other words, one must use just "tablename" not "database.tablename"
# when specifying the table.

The ORDER BY and LIMIT clauses on UPDATE and DELETE statements are not
supported. ORDER BY and LIMIT are not normally supported for UPDATE or
DELETE in any context but can be enabled for top-level statements
using the SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option. However,
that compile-time option only applies to top-level UPDATE and DELETE
statements, not UPDATE and DELETE statements within triggers.

/* IMP: R-43310-35438 */

# EVIDENCE-OF: R-43310-35438 The ORDER BY and LIMIT clauses on UPDATE
# and DELETE statements are not supported. ORDER BY and LIMIT are not
# normally supported for UPDATE or DELETE in any context but can be
# enabled for top-level statements using the
# SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option. However, that
# compile-time option only applies to top-level UPDATE and DELETE
# statements, not UPDATE and DELETE statements within triggers.

If one or more ON INSERT, ON DELETE
or ON UPDATE triggers are defined on a view, then it is not an
error to execute an INSERT, DELETE or UPDATE statement on the view,
respectively.

/* IMP: R-36338-64112 */

# EVIDENCE-OF: R-36338-64112 If one or more ON INSERT, ON DELETE or ON
# UPDATE triggers are defined on a view, then it is not an error to
# execute an INSERT, DELETE or UPDATE statement on the view,
# respectively.

# EVIDENCE-OF: R-58080-31767 Note that the sqlite3_changes() and
# sqlite3_total_changes() interfaces do not count INSTEAD OF trigger
# firings, but the count_changes pragma does count INSTEAD OF trigger
# firing.

Assuming that customer records are stored in the "customers" table, and
that order records are stored in the "orders" table, the following
UPDATE trigger
ensures that all associated orders are redirected when a customer changes
his or her address:

# EVIDENCE-OF: R-16646-21584 Assuming that customer records are stored
# in the "customers" table, and that order records are stored in the
# "orders" table, the following UPDATE trigger ensures that all
# associated orders are redirected when a customer changes his or her
# address: CREATE TRIGGER update_customer_address UPDATE OF address ON
# customers BEGIN UPDATE orders SET address = new.address WHERE
# customer_name = old.name; END; With this trigger installed, executing
# the statement: UPDATE customers SET address = '1 Main St.' WHERE name
# = 'Jack Jones'; causes the following to be automatically executed:
# UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack
# Jones';

When one of RAISE(ROLLBACK,...), RAISE(ABORT,...) or RAISE(FAIL,...)
is called during trigger-program
execution, the specified ON CONFLICT processing is performed
the current query terminates.

/* IMP: R-30235-58964 */

# EVIDENCE-OF: R-30235-58964 When one of RAISE(ROLLBACK,...),
# RAISE(ABORT,...) or RAISE(FAIL,...) is called during trigger-program
# execution, the specified ON CONFLICT processing is performed the
# current query terminates.

When RAISE(IGNORE) is called, the remainder of the current trigger program,
the statement that caused the trigger program to execute and any subsequent
trigger programs that would have been executed are abandoned.

/* IMP: R-10546-57588 */

# EVIDENCE-OF: R-10546-57588 When RAISE(IGNORE) is called, the remainder
# of the current trigger program, the statement that caused the trigger
# program to execute and any subsequent trigger programs that would have
# been executed are abandoned.

If the statement that caused the trigger program
to execute is itself part of a trigger program, then that trigger program
resumes execution at the beginning of the next step.

/* IMP: R-01402-03601 */

# EVIDENCE-OF: R-01402-03601 If the statement that caused the trigger
# program to execute is itself part of a trigger program, then that
# trigger program resumes execution at the beginning of the next step.

A trigger normally exists in the same database as the table named
after the "ON" keyword in the CREATE TRIGGER statement. Except, it is
possible to create a TEMP TRIGGER on a table in another database.

/* IMP: R-56934-42700 */

# EVIDENCE-OF: R-56934-42700 A trigger normally exists in the same
# database as the table named after the "ON" keyword in the CREATE
# TRIGGER statement. Except, it is possible to create a TEMP TRIGGER on
# a table in another database.