Watch for a table new records in sql database

Here are my propositions:

  1. If you are able to add duplicate table to database then here is a solution. You have your table1 and table2 (Copy of table1). When you inserting new records to table1, you can compare them with existing records in your table2 and thus find new records. After comparing you should add all new records to table2. This is some kind of synchronization. This can be made via stored proc or programatically.

  2. You don’t need any another tables. You can store all your data in your app cache and check with some period of time (for example 5secs) are there any new events, that aren’t exist in your cache. If they aren’t exist – notify them in your log or somewhere else and add them to cache. But if there are too many records, the processing time will be greatly increased + memory consumption.

  3. If you are able to change db then you can add something like ‘isNew’ column to your table. When a new data came from the website, the column will be ‘true’, your program can track this, and after processing set this flag to false for each record. (If the website can’t set this flag, you can use SQL TRIGGER AFTER INSERT to set the flag value to true. Website can’t even know about this feature if it is third-party web site or you don’t want to change anything there)

  4. Here is article about EF changes tracking:
    http://blogs.msdn.com/b/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx

But the problem is that you should check whole table for changes via EF that will hit your app performance.

Here are useful info about SQL Server side change tracking and implementation concepts:
http://www.mssqltips.com/sqlservertip/1819/using-change-tracking-in-sql-server-2008/
http://msdn.microsoft.com/en-us/library/bb933994.aspx

Leave a Comment