English 中文(简体)
Is there an easy way to track all changes in a SQL 2005 Database
原标题:

I ve been tasked with hooking in our product with another third party product. One of the things I need to do is mimic some of the third-party s product functionality when adding new "projects" - which can touch several database tables. Is there any way to add some kind of global hook to a database that would record all changes made to data?

I d like to add the hook, create a project using the third-party application, then check out what all tables were affected.

I know it s more than just new rows as well, I ve come across a number of count fields that look to be incremented for new projects and I worry that there might be other records that are modified on a new project insert, and not just new rows being added.

Thanks for any help ~Prescott

最佳回答

I can think of the following ways you can track changes

  1. Run SQL Server Profiler which will capture all queries that run on the server. You can filter these by database, schema or a set of tables, etc.
  2. Use a 3rd party Transaction Log reader. This is very much a less intrusive process. You have to ensure that you are set to FULL recovery on the database.
问题回答

Make sure the log will not be reused:

  • the database is in full recovery mode (true full, with an initial backup)
  • the log backup maintenance tasks are suspended for the duration of the test

Then:

  • write down the current database LSN
  • run your 3rd party project create
  • check the newly added log information with select * from ::fn_log(oldcurrentLSN, NULL);

All write operations will apear in the log. From the physical operation (allocation unit ID) you can get to the logical operation (object id).

Now that being said, you should probably have a decent understanding of the 3rd party schema and data model if you plan to interact with it straight at the database level. If you are planning to update the 3rd party tool and you don t even know what tables to update, you ll more than likely end up corrupting its data.





相关问题
SQL Server database is not visible

I have installed ASP.NET application with database on our server. ASP.NET application created database using connection string below. The problem is that I do not see database in SQL Server Management ...

Most efficient way to store number 11.111 in SQL Server

What datatype is the most efficient to store a number such as 11.111. The numbers will have up 2 digits before the point and up to three after. Currently the column is a bigint , I am guessing that ...

表格和数据表

是否需要在提瓜表之后更新表格统计数据,还是自动更新?

Inconsistent Generate Change Script

I add a column of type tinyint and being set to not allow nulls in a table and generate the change scripts. The table has data in it at this time. The script has code that creates a temp table and ...

Performance of Sql subqueriesfunctions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have ...

selecting one value out of an xml column

I have a particularly troublesome xml column to query data from. The schema is fixed by the Quebec Ministry of Revenue so "it is what it is" The important part of the query looks like this: with ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签