Update Trigger

  1. 2 months ago

    Dave S

    Jul 9 San Diego, California USA

    I have a trigger similar to this

    CREATE TRIGGER modTRIGGER AFTER UPDATE OF
    field1,field2,field3
    ON myTABLE
    BEGIN
    UPDATE myTABLE
     SET modDATE=datetime()
    WHERE key=old.key

    Does this fire when any one (Field1, Field2 or Field3) changes? or do they ALL have to be changed?
    If I do an UPDATE and set the values to what they already are does this fire?

    CREATE TRIGGER modTRIGGER AFTER UPDATE ON myTABLE
    where new.field1 <> old.field1
    or new.field2 <>old.field2
    or new.field3 <>old.field3

    BEGIN
    UPDATE myTABLE
    SET modDATE=datetime()
    WHERE key=old.key

  2. Dave S

    Jul 9 Answer San Diego, California USA

    CREATE TRIGGER modTRIGGER AFTER UPDATE ON myTABLE
    where new.field1 <> old.field1
    or new.field2 <>old.field2
    or new.field3 <>old.field3

    BEGIN
    UPDATE myTABLE
    SET modDATE=datetime()
    WHERE key=old.key

  3. Joost R

    Jul 9 Pre-Release Testers, Xojo Pro The Netherlands

    Hi Dave, your sample is for SQLite so to see. Mind that the implementation of triggers differs for database types like MySQL, PostgreSQL etc.

  4. Dave S

    Jul 10 San Diego, California USA

    yes this is for SQLite

or Sign Up to reply!