Search code examples
sqltriggersinterbase

Interbase SQL trigger


Interbase, Sql, trigger. Can't really understand how to write a trigger of this kind: I have several tables. Each one has a document type, status and an unique number. One table in which i wish to create a trigger is a table that holds a file i post, a status of posting, a doctype corresponding to a table and a unique number linking to a record in the corresponding table. I want to change document status in the corresponding table based on the unique number to a certain status depending on the post result (status) that i change after posting. How can I do it?


Solution

  • Trigger T1 will be executed after update on TABLE1.

    Trigger checks if TABLE1.StatusOfPosting changed to some value and depending on result updates TABLE2.DocumentStatus.

    Depending on bussienes logic, maybe you will need and BEFORE DELETE trigger.

    CREATE TRIGGER T1 FOR TABLE1 AFTER UPDATE POSITION 0
    AS
    BEGIN
      IF (NEW.StatusOfPosting <> OLD.StatusOfPosting and NEW.StatusOfPosting=1) THEN
        UPDATE TABLE2
        SET TABLE2.DocumentStatus=1
        WHERE TABLE2.UniqueNumber = TABLE1.UniqueNumber;
    END