Name
CREATE TRIGGER — Create a new trigger action
Syntax
Common Usage
CREATE TRIGGERdatabase_name
.trigger_name
BEFORE INSERT ONtable_name
FOR EACH ROW BEGINstmt1
;stmt2
; END; CREATE TRIGGER access_audit BEFORE UPDATE ON access FOR EACH ROW BEGIN INSERT INTO audit_trail VALUES ( OLD.level, NEW.level, CURRENT_TIMESTAMP ); END;
Description
The CREATE
TRIGGER
command creates a trigger and binds it
to a table or view. When the conditions defined by the trigger
are met, the trigger will “fire,” automatically executing
statements found in the trigger body (the part between BEGIN
and END
). A table or view may have
any number of triggers associated with it, including multiple
triggers of the same type.
If the optional TEMP
or TEMPORARY
keyword is present, a trigger will be
created in the temp
database.
A trigger can also be made temporary by qualifying the trigger
name with the database name temp
. If the trigger name is qualified with a
database name, specifying TEMP
or TEMPORARY
will result in an error, even if the
given database name is temp
.
Temporary triggers can be attached to either temporary or standard (nontemporary) tables. A specific table instance can be chosen by qualifying the table name with a database name. In all other cases, the trigger and the table should be in the same database. Either the trigger name or the table name can be qualified with a database name (or both, if they ...
Get Using SQLite now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.