标签云

微信群

扫码加入我们

WeChat QR Code

How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is .NET and C#.I'd like to be able to support any SQL Server 2000 SP4 or newer. My application is a bolt-on data visualization for another company's product. Our customer base is in the thousands, so I don't want to have to put in requirements that we modify the third-party vendor's table at every installation.By "changes to a table" I mean changes to table data, not changes to table structure.Ultimately, I would like the change to trigger an event in my application, instead of having to check for changes at an interval.The best course of action given my requirements (no triggers or schema modification, SQL Server 2000 and 2005) seems to be to use the BINARY_CHECKSUM function in T-SQL. The way I plan to implement is this:Every X seconds run the following query:SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*))FROM sample_tableWITH (NOLOCK);And compare that against the stored value. If the value has changed, go through the table row by row using the query:SELECT row_id, BINARY_CHECKSUM(*)FROM sample_tableWITH (NOLOCK);And compare the returned checksums against stored values.


They didn't happen to put a last-modified timestamp on their rows, did they?

2019年08月20日05分20秒

Checksums can and will fail eventually. If your system accepts that two different sets of data will result in the same checksum, than you are fine. For that reason, I had to move away from checksums in most of our systems...

2019年08月19日05分20秒

LPains can you please elaborate on your statement?

2019年08月19日05分20秒

petrosmm I'm not sure what specifically you want me to elaborate, but I will try. Imagine you have a table with a few hundred records, you essentially generate an integer as a checksum, how often is that going to collide? In my case, I was doing that with about 10 tables, all with hundreds of records. I had at least one collision per day. Check this other answer stackoverflow.com/questions/14450415/…

2019年08月19日05分20秒

Thank you LPains!

2019年08月19日05分20秒

That's not actually an answer, it's a "your suggestion doesn't work".

2019年08月19日05分20秒

This can be remedied for duplicated data by using the DISINCT keyword before the BINARY_CHECKSUM.There are a few other pitfalls discussed here but not exactly common scenarios.

2019年08月19日05分20秒

The question is about changes in table data and information_schema contains schema (column definitions) of the table.

2019年08月19日05分20秒

Please provide a documented way of getting this information scoped to a table in SQL Server

2019年08月19日05分20秒