• Keep in mind that this only works when the view is updated and not the underlying table changes that make up the view. If you need to track the changes made to the underlying tables that make up the view you will have to create multiple triggers, one on each table, and/or just create a procedure to handle everything.

    IF OBJECT_ID('tr_view_badge') IS NOT NULL

    DROP TRIGGER tr_view_badge

    go

    create trigger tr_view_badge

    on view_badge

    instead of insert, update, delete

    as

    BEGIN

    DECLARE @action CHAR(1)

    IF(EXISTS(SELECT * FROM inserted) AND EXISTS(SELECT * FROM deleted))

    SET @action = 'U'

    ELSE IF(EXISTS(SELECT * FROM inserted))

    SET @action = 'I'

    ELSE IF(EXISTS(SELECT * FROM deleted))

    SET @action = 'D'

    IF @action IS NULL

    return

    --Do what you need to the table based on the action

    END

    GO