

Thereafter, executing an INSERT, DELETE or UPDATE on the view causes the associated triggers to fire. 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. Triggers may be created on views, as well as ordinary tables, by specifying INSTEAD OF in the CREATE TRIGGER statement. Triggers are automatically dropped when the table that they are associated with is dropped. However if an ON CONFLICT clause is specified as part of the statement causing the trigger to fire, then this conflict handling policy is used instead. The specified trigger-time determines when the trigger-steps will be executed relative to the insertion, modification or removal of the associated row.Īn ON CONFLICT clause may be specified as part of an UPDATE or INSERT trigger-step. If no WHEN clause is supplied, the SQL statements are executed for all rows.

If a WHEN clause is supplied, the SQL statements specified as trigger-steps are only executed for rows for which the WHEN clause is true. OLD and NEW references may only be used in triggers on trigger-events for which they are relevant, as follows: FOR EACH ROW implies that the SQL statements specified as trigger-steps 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.īoth the WHEN clause and the trigger-steps 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. Hence explicitly specifying FOR EACH ROW is optional. Triggers are database operations (the trigger-action) that are automatically performed when a specified database event (the database-event) occurs.Ī trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a particular database table occurs, or whenever an UPDATE of one or more specified columns of a table are updated.Īt this time SQLite supports only FOR EACH ROW triggers, not FOR EACH STATEMENT triggers. The CREATE TRIGGER statement is used to add triggers to the database schema.
