我应该如何在不使用触发器的情况下跟踪数据库中的删除操作?
应用程序会在一定时间间隔后轮询数据库。在每次轮询中,应用程序都会读取所有表。
作为优化的一部分,我们希望应用程序仅在发生任何 INSERT/UPDATE/DELETE 时才读取表。所以我想使用时间戳概念。
拥有单独的时间戳列可以帮助我跟踪任何行修改。
在查询表时,我可以检查内存中存储的时间戳是否小于表中的最大时间戳。如果是,则意味着某些行已被修改。
但是,如果某行被删除,则与该行相关的最新时间戳将不再存在。因此,上述算法在这种情况下会失败,因为最大时间戳没有给出正确的值。
有没有一种方法可以让我在不使用触发器的情况下跟踪删除操作?
任何帮助将不胜感激。 我正在使用 Sybase ASA 数据库。
The appliocation polls the database after certain intervals of time. On each polling, the application would read all the tables.
As a part of optimization, we want that application should read the table only if any INSERT/UPDATE/DELETE has happened. So i want to use the timestamp concept.
Having a seperate timestamp column can help me in tracking any row modifications.
While querying on a table i can check if the in-memory stored timestamp is lesser than the max-of-TimeStamp in the table. if yes, it means that some row has been modified.
But if certain row gets deleted, then the latest timestamp assosiated with this row is no more pressent. Hence the above algorithm fails in this case since the max-of-timestamp does not give the correct value.
Is there a way in which i can track the delete operations as well without using triggers?
Any help would be highly appreciated.
I am using Sybase ASA database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以实现逻辑删除。例如,您只需使用特定标志将其标记为已删除,而不是删除记录。
您仍然具有最大时间戳,并且可以从选择查询中排除标记的记录(也许在表顶部创建一些视图来自动完成这项工作)。
Maybe you could implement a logical deletion. Instead of removing a record you simply mark it as deleted with a specific flag for example.
You still have the max timestamp and you can exclude the flagged records from the selection queries (maybe create some views on top of the table to do the job automatically).