Trigger to prevent update when Flag value is 1 I need help with a trigger to prevent update on any column except for column Flag (it can be updated) when Flag value is 1 on the below table:

CREATE TABLE Tmp (Id INT, Type INT, TranDate DATE, Flag INT)
INSERT INTO Tmp VALUES (1, 2, '2017-04-24', 0)
INSERT INTO Tmp VALUES (2, 4, '2017-04-27', 1)


I've tried with the below code but doesn't work correctly.

CREATE TRIGGER [dbo].[Prevent_Update_Trigger]
ON [dbo].[Tmp]
FOR UPDATE
AS
SET NOCOUNT ON
IF  EXISTS(SELECT NULL FROM dbo.Tmp t JOIN inserted i ON t.Id=i.Id AND t.Flag=1)
BEGIN
RAISERROR('You can not update when Flag value is 1', 16, 1)
ROLLBACK TRAN
SET NOCOUNT OFF
RETURN
END
SET NOCOUNT OFF
CREATE TRIGGER dbo_Tmp_trg_AU
ON dbo.Tmp
AFTER UPDATE
AS
BEGIN
    SET ROWCOUNT 0;
    SET NOCOUNT ON;

    IF EXISTS
    (
        SELECT NULL
        FROM Deleted AS Del
        WHERE
            -- Originally, flag was 1
            Del.Flag = 1
            AND NOT EXISTS
            (
                -- Column(s) aside from Flag have changed
                SELECT
                    Del.[Type],
                    Del.TranDate
                INTERSECT
                SELECT
                    Ins.[Type],
                    Ins.TranDate
                FROM Inserted AS Ins
                WHERE
                    -- Same Id
                    Ins.Id = Del.Id
            )
    )
    BEGIN
        RAISERROR ('You can not update when Flag value is 1', 16, 1);
        ROLLBACK TRANSACTION;
        RETURN;
    END;
END;


This assumes the Id column cannot be updated (e.g. it is an IDENTITY column).