Track table row deletion

  • What is the best way to track the user who deletes any records in a specified table?

    User information, such as machine name, login name etc, needs to be logged.

  • You can write a DB trigger For delete statements and Stored the username,currentdate,Servername in another table ...Just look the Example

    create trigger tr_delete_log on dbo.TableA --(Table where delete occurs)

    for delete

    as

    insert into dbo.DeleteLog--New table containing username,currentdate,Servername

    select SUSER_NAME(),getdate(),HOST_NAME()

    GO

  • Another option is

    1) Don't give delete permission to normal users

    2) Allow delete only from the stored procedure. In the stored procedure, save the required information.

  • One another option is CDC (Change Data Capture).

  • Can CDC capture specifically Delete statements?

  • That question is too large for a forum thread... read on all you need here :

    http://msdn.microsoft.com/en-us/library/bb522489.aspx

  • Thanks, ninja.

Viewing 7 posts - 1 through 6 (of 6 total)

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