Re: Activity Monitoring for a Single Table

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



William (Bill) Corder (wscorder@xxxxxxxxxxx) writes:
We started experiencing a strange problem with one of our database last
week. After analyzing the data and comparing with multiple backup sets,
we found that data was randomly being deleted from a single table.

Is there any way to monitor a single table for activity, add, delete,
change, etc? We want to do this for a day or so to identify the
offending process.

A trigger that logs the deleted rows together with columns populated with
the output from host_name(), app_name(), SYSTEM_USER, getdate() etc is
definitely what you need.

A server-side trace as Aaron suggested gives you the offending statement
more directly, so that is also a good idea. The log table gives you what
was deleted and when, and from that you can look up the trace.

I had to do this recently. Except that I did not come very far. That is,
before I deployed my trigger to production, I tested it, and when I ran
a delete operation from the GUI, I found that the log table said that
two rows had been deleted. Oh-oh. The culprit was a DELETE statement in
a procedure where I had forgotten the WHERE clause, blush!

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Query training -- Complex queries
    ... > Update PositionsEOM ... Here you don't have a derived table, but a correlated subquery. ... UPDATE in Books Online. ... is not written for SQL Server. ...
    (microsoft.public.sqlserver.server)
  • Re: Linked Server: How to check if server exists?
    ... The root problem is described in the Books Online topic Batches. ... Rick Byham, SQL Server Books Online ... linked server don't run on those development machines not having that linked ...
    (microsoft.public.sqlserver.connect)
  • Re: STORED PROCEDURE - passing table name as a parameter
    ... T-SQL, is that you get problems if the view definition does not fit into ... will need to query other system tables, for instance syscolumns. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Problem when changing Views
    ... There aree several reasons. ... I use neither of the tools, but I guess that Design View resubmits the ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: SQL 2005: Help files not valid?
    ... Please try the following instructions to remove and reinstall Books Online. ... If this doesn't solve the problem, we'll need to get the Visual Studio folks ... In Add or Remove Programs, select Microsoft SQL Server 2005, and then ... Complete the remaining steps in the Installation Wizard. ...
    (microsoft.public.sqlserver.setup)