Here, event_name could be INSERT, DELETE, and UPDATE database operation on the mentioned table table_name. The table to be modified must exist in the same database as the table or view to which the trigger is attached and one must use just tablename not database.tablename.Ī special SQL function RAISE() may be used within a trigger-program to raise an exception.įollowing is the basic syntax of creating a trigger.ĬREATE TRIGGER trigger_name event_name Triggers are automatically dropped when the table that they are associated with is dropped. The BEFORE or AFTER keyword determines when the trigger actions will be executed relative to the insertion, modification, or removal of the associated row. If no WHEN clause is supplied, the SQL statements are executed for all rows. If a WHEN clause is supplied, the SQL statements specified are only executed for rows for which the WHEN clause is true. Hence, explicitly specifying FOR EACH ROW is optional.īoth 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. SQLite trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a particular database table occurs or whenever an UPDATE occurs on one or more specified columns of a table.Īt this time, SQLite supports only FOR EACH ROW triggers, not FOR EACH STATEMENT triggers. Following are the important points about SQLite triggers − SQLite Triggers are database callback functions, which are automatically performed/invoked when a specified database event occurs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |