Trigger question for partial rollback

  • Hello:

    My trigger fires when I want it to but if I have a transaction with multiple INSERT statements it wipes them all out.  I only want it to ignore the INSERTS that meet a certain criteria (dscrptn = garbage or trash).  Anything else should be allowed into tblMyLog.  Code below is what I have thus far. SQL Server 2000.

    Ideas? 

    CREATE TRIGGER [trgTest] ON [dbo].[tblMyLog]

    FOR INSERT

    AS

    DECLARE @desc varchar(132)

    SELECT @desc = dscrptn

    FROM inserted

    IF (@desc = 'garbage') or (@desc = 'trash')

    BEGIN

       RAISERROR ('INSERT Ignored (trgTest)', 16, 1)

       ROLLBACK TRANSACTION

    END

    Thank you

  • Do not use an "AFTER INSERT" trigger, but try using an "INSTEAD OF INSERT" trigger

    that inserts into the same table.

    CREATE TRIGGER [trgTest]

    ON [dbo].[tblMyLog]

    FOR INSTEAD OF INSERT

    AS

    set nocount on

    set xact_abort on

    if @@ROWCOUNT = 0 RETURN

    INSERT into tblMyLog

    select *

    from inserted

    where dscrptn not in ('garbage', 'trash')

    go

    SQL = Scarcely Qualifies as a Language

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply