每个字段与历史日期字段的版本控制?
您推荐哪一个以及为什么?
我有几个表,当我对数据进行更改时......它应该转到带有有效日期的历史表(审核)。
另一个解决方案是对每个字段进行版本控制以在更改数据时插入新行?
获取发票信息的最佳方法是什么?商品名称和价格随时变化
Which do you recommend and why?
I have a few tables, when i make a change to the data... it should go to a history table (audit) with a effective date.
The other solution is versioning each field to insert a new row when making changes to the data?
Which is the best method for the invoice information? Item name and price is always change
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它们是缓慢变化的维度、
类型 2
和类型 4
,适当地。这两种方法都是有效的,并且可能更适合您的需求,具体取决于您的模型和查询要求。
基本上,当您需要像当前值一样频繁地查询历史值时,
类型 2
(版本控制)更合适,而当您需要查询历史值时,类型 4
(历史表)更合适。更频繁地查询当前值,并且针对最新值有更多查询(我的意思是需要开发更多查询)。These are slowly changing dimensions,
type 2
andtype 4
, appropriately.Both methods are valid and may be more appropriate for your needs, depending on your model and query requirements.
Basically,
type 2
(versioning) is more appropriate when you need to query historical values as often as the current one, whiletype 4
(history table) is more suited when you are querying the current value more often and there are more queries (more queries to develop I mean) against the most recent value.我们使用并满意的系统:
每个需要历史记录的表,我们都创建一个类似的表,并在末尾添加时间戳字段,该字段成为 PK 的一部分。
每次对原始表进行更新时,我们都会以相同的条件插入到历史表中:
这可以保持数据干净且表精简。
A system we use and happy with:
Each table that requires history, we create a similar table and adding a timestamp field at the end, which becomes a part of the PK.
Each update on original table, we insert into history table with the same conditions:
That keeps your data clean and your tables slim.
我个人的偏好是在应用程序中使用观察者模式并实现一个单独的历史记录表。这意味着您可以在需要时从历史表中提取数据,并且不会影响查询主表的速度。
My personal preference would be to user the Observer Pattern in your application and to implement a separate history table. This means that you can pull the data from the history table when you need it and you don't compromise the speed of querying the main table.