每个表的last_update时间戳?
在每个表中为最后一行更新添加时间戳是一个好习惯吗?
或者应该只在真正需要的地方设置它们? 我如何知道稍后哪里需要更新时间戳? 它们对哪种信息有意义?
Is it a good practice to have timestamps for the last row update in every table?
Or should they only be set where really needed?
How do I know where I will need an update timestamp later?
For which kind of information do they make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
行时间戳用于在具有乐观记录锁定的情况下进行行版本控制;即2个用户同时编辑同一条记录。
您可以通过检查当前行时间戳以及从数据库检索行时找到的时间戳来检测数据库版本是否已更改。
row timestamps are used for row versioning in situations where you have optimistic record locking; i.e. 2 users editing the same record at the same time.
You can detect if the DB version has changed, by examining the current row timestamp with the timestamp found when you retrieved the row from the DB.
将其保留在用于捕获事务的表中是一个更好的决定。它可能适用于日志记录/安全性,也可能用于处理并发性。
Its a better decision to keep it in the tables used to capture transactions. It might work for logging/security or might be used to handle concurrency.
我认为开始向表添加“last_updated”时间戳是一个滑坡。所以你可能会问“这一行什么时候改变的?”但是一旦您添加了 last_updated 列,他们就会问:“好吧,6 天前已更改。更改了什么?”。因此,现在您必须设置一个“历史”表,其中包含所有更改的列。但随后他们会问:“好吧,‘foo’列在 6 天前被更改了,之前的值是多少?”现在您可以跟踪整个数据库中每一行的完整历史记录!
I think it's a slippery slope to start adding "last_updated" timestamps to tables. So you might have people asking "when was this row changed?" but as soon as you add a last_updated column, they're going to ask, "OK, it was chnged 6 days ago. What was changed?". So now you have to set up a "history" table with all of the columns that changed. But then they ask, "Well, the 'foo' column was changed 6 days ago, what was the previous value?" And now you're keeping track of the complete history of every row in the entire database!
我认为真正的问题是你想用这些时间戳做什么。如果您的应用程序没有实际需要它,那么我认为没有充分的理由存储和维护该数据。
I think the real question is what you would want to use those timestamps for. If your application has no actual need for it, then I don't see a strong case for storing and maintaining that data.