Skip to Main Content
Using SQLite
book

Using SQLite

by Jay A. Kreibich
August 2010
Intermediate to advanced content levelIntermediate to advanced
526 pages
23h 39m
English
O'Reilly Media, Inc.
Content preview from Using SQLite

Name

CREATE TRIGGER — Create a new trigger action

Syntax

image with no caption

Common Usage

CREATE TRIGGER database_name.trigger_name BEFORE INSERT ON table_name FOR EACH ROW
  BEGIN stmt1; 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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning SQL, 3rd Edition

Learning SQL, 3rd Edition

Alan Beaulieu
High Performance MySQL, 4th Edition

High Performance MySQL, 4th Edition

Silvia Botros, Jeremy Tinley

Publisher Resources

ISBN: 9781449394592Errata PageSupplemental Content