Hi

I have a AFTER UPDATE trigger that I want to be called only during an UPDATE SQL statement. Part of the schema is below

CREATE TABLE data (

ref  INTEGER NOT NULL PRIMARY KEY ON CONFLICT ROLLBACK,
key_ref INTEGER NOT NULL,
value BLOB NOT NULL,
reason BLOB NOT NULL DEFAULT "Initial version",
user BLOB NOT NULL DEFAULT "unknown",
timestamp TEXT NOT NULL DEFAULT "none"

);

CREATE TABLE data_history (

ref  INTEGER NOT NULL PRIMARY KEY ON CONFLICT ROLLBACK,
data_ref INTEGER NOT NULL,
value BLOB NOT NULL,
reason BLOB NOT NULL,
user BLOB NOT NULL,
timestamp TEXT NOT NULL

);

CREATE TRIGGER create_data_history AFTER UPDATE ON data
   BEGIN
      INSERT INTO data_history (data_ref, value, reason, user, timestamp)
VALUES (OLD.ref, OLD.value, OLD.reason, OLD.user, OLD.timestamp);
   END;


The problem occurs when I insert a new record into the table data. For some reason the create_data_hisotry trigger is executed. Could someone explain this to me.

Many Thanks
Nick




Reply via email to