how to create trigger for delete

  • Hi

    I want to know how can I prevent my table through trigger that

    nobody can delete the records from table.

  • Try using INSTEAD OF triggers:

    CREATE TABLE Test (

    col1 int

    )

    GO

    CREATE TRIGGER TR_TEST ON Test

    INSTEAD OF DELETE

    AS

    BEGIN

    DECLARE @pr int

    SET @pr = 0

    END

    GO

    INSERT INTO Test values(1)

    SELECT * FROM Test

    And you'll get:

    col1

    -----------

    1

    DELETE FROM Test

    SELECT * FROM Test

    And you'll get:

    col1

    -----------

    1

    Hope this helps.

    -- Gianluca Sartori

  • Thanks for help.

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

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