且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

监视sql数据库中的表新记录

更新时间:2023-02-08 16:29:59

以下是我的建议:

  1. 如果您能够将重复表添加到数据库,那么这里有一个解决方案.您有 table1table2(table1 的副本).当您向 table1 插入新记录时,您可以将它们与 table2 中的现有记录进行比较,从而找到新记录.比较后,您应该将所有新记录添加到 table2.这是某种同步.这可以通过存储过程或以编程方式进行.

  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.

您不需要任何其他表.您可以将所有数据存储在应用程序缓存中,并在一段时间内(例如 5 秒)检查是否有任何新事件,这些事件不存在于您的缓存中.如果它们不存在 - 在您的日志或其他地方通知它们并将它们添加到缓存中.但是如果记录太多,处理时间会大大增加+内存消耗.

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.

如果您能够更改数据库,那么您可以向您的表中添加类似isNew"列的内容.当网站有新数据时,该列将为真",您的程序可以跟踪这一点,并在处理后为每条记录将此标志设置为假.(如果网站不能设置这个标志,你可以使用SQL TRIGGER AFTER INSERT将标志值设置为true.如果是第三方网站,网站甚至不知道这个功能或者你不想在那里改变任何东西)

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)

这是关于 EF 更改跟踪的文章:http://blogs.msdn.com/b/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx

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

但问题是您应该通过 EF 检查整个表是否有会影响您的应用程序性能的更改.

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

以下是有关 SQL Server 端更改跟踪和实现概念的有用信息:http://www.mssqltips.com/sqlservertip/1819/using-change-tracking-in-sql-server-2008/http://msdn.microsoft.com/en-us/library/bb933994.aspx

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