Limiting the number of updates on a table using Trigger

  • Hi All,

     

    I was wondering if there was a way in which a particular user can be audited for updates on a table, eg

    I normally have users performing updates without using the where clause, I was wondering if there was a trigger in which I can use to check if a user has updated more than 10 rows, then rollback and throw an error message saying, ohhh, speak to Manager.

    Thanks in advance

     

     


    Kindest Regards,

    John Burchel (Trainee Developer)

  • You need something like this :

    CREATE

    TRIGGER dbo.trTableName_F_U ON dbo.TableName

    FOR

    UPDATE

    AS

    SET NOCOUNT ON

    IF 10 < (SELECT COUNT(*) FROM DELETED)

    BEGIN

    ROLLBACK TRANSACTION

    RAISERROR ('Cannot update more than 10 rows at the time on table TableName', 13, 1)

    END

    GO

  • Thanks for this, worked a treat


    Kindest Regards,

    John Burchel (Trainee Developer)

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

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