How can I get a list of modified records from a SQL Server database?

Posted by Pixelfish on Stack Overflow See other posts from Stack Overflow or by Pixelfish
Published on 2010-05-19T15:22:34Z Indexed on 2010/05/19 15:30 UTC
Read the original article Hit count: 184

Filed under:

I am currently in the process of revamping my company's management system to run a little more lean in terms of network traffic. Right now I'm trying to figure out an effective way to query only the records that have been modified (by any user) since the last time I asked.

When the application starts it loads the job information and caches it locally like the following: SELECT * FROM jobs.

I am writing out the date/time a record was modified ala UPDATE jobs SET Widgets=@Widgets, LastModified=GetDate() WHERE JobID=@JobID.

When any user requests the list of jobs I query all records that have been modified since the last time I requested the list like the following: SELECT * FROM jobs WHERE LastModified>=@LastRequested and store the date/time of the request to pass in as @LastRequest when the user asks again. In theory this will return only the records that have been modified since the last request.

The issue I'm running into is when the user's date/time is not quite in sync with the server's date/time and also of server load when querying an un-indexed date/time column. Is there a more effective system then querying date/time information?

© Stack Overflow or respective owner

Related posts about sql-server