• Option (1) should be fine as long as the trigger is efficiently written and there is an index to support the trigger's query. For example, if the table is clustered on ( alarmNumber, ID ) rather than on just ID.

    CREATE TRIGGER table_name__trg_insert

    ON table_name

    INSTEAD OF INSERT

    AS

    INSERT INTO table_name

    SELECT i.eventTime, i.alarmNumber, i.alarmState

    FROM inserted i

    OUTER APPLY (

    SELECT TOP (1) *

    FROM table_name tn

    WHERE tn.alarmNumber = i.alarmNumber

    ORDER BY ID DESC

    ) AS prev_alarm

    WHERE prev_alarm.alarmState <> i.alarmState OR prev_alarm.alarmState IS NULL

    GO

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.