Popiel
Popiel

Reputation: 193

SQLite - Create Trigger for Insert or Update

Is this possible to create one trigger for Insert and Update operations in SQLite? I mean, something like this:

CREATE TRIGGER dbo.TR_TableName_TriggerName
    ON dbo.TableName
    AFTER INSERT, UPDATE, DELETE
AS
BEGIN
    SET NOCOUNT ON;

    IF NOT EXISTS(SELECT * FROM INSERTED)
        -- DELETE
        PRINT 'DELETE';
    ELSE
    BEGIN
        IF NOT EXISTS(SELECT * FROM DELETED)
            -- INSERT
            PRINT 'INSERT';
        ELSE
            -- UPDATE
            PRINT 'UPDATE';
    END
END;

It's for MS SQL i think, source: Insert Update trigger how to determine if insert or update


Edit: Is it possible to create also one trigger for more than one table?

Upvotes: 6

Views: 9627

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181077

No, the syntax graph for CREATE TRIGGER clearly shows that only one of INSERT, UPDATE or DELETE can be given.

It also shows that only one table can be given as a table to trigger on.

Upvotes: 14

Related Questions