Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 700
Popiel Avatar asked Jul 19 '26 07:07

Popiel


1 Answers

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.

like image 119
Joachim Isaksson Avatar answered Jul 22 '26 04:07

Joachim Isaksson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!