简体   繁体   中英

How can I tell if a database record has changed?

I'm writing a process that will run on a schedule and periodically scan records in a SQL Server database and check for changes to those records. Unfortunately the records in this database are not versioned/timestamped in any way and I can't change the schema because it's not my database. Short of comparing every single field I don't have any idea how to check to see if a change has actually occurred.

Right now I'm using entity framework for all data access, but I can switch to direct queries if needed. Is there an easy way to do this?

EDIT: I need a way to check each individual record for changes, not a database/table as a whole.

I don't think checking each record can work for big databases (it can take forever)

But you could calculate hash for each row and store it in your apps database. Then on every run recalculate hash and compare with what's in your apps db.

Also I know you can't change schema, but maybe you could add triggers to monitored dataabse that will log changes?

Another option could be setting up replication and detecting changes (with triggers as above) in database that receive's replicated data (but I have to admit I never configured replication and I may be wrong about how it works).

If you're using SQL Server 2008 or greater, you may be able to make use of either Change Data Capture or Change Tracking. Here's a link to the MSDN documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM