有关 items_for_sale 随着时间的推移更新的数据库/架构设计问题

发布于 2024-09-08 20:58:39 字数 276 浏览 1 评论 0原文

我知道我的问题的明显答案是:“这取决于”。有了这个,我希望你们中的一个(或多个)能帮助我找到解决这个问题的常见方法......

我正在设计一个待售小部件的数据库。随着时间的推移,每件商品的价格将不可避免地发生变化。我的问题是我们是否应该跟踪这些变化?如果是,如何跟踪?相关定价表日期?跟踪价格变化是否很常见,这样您就可以回顾 3 年后的情况,看看发生了什么变化以及何时发生变化。我可以看出这很有价值,但是值得付出这些开销吗?

订单表将捕获销售日期的当前价格。

想法?

谢谢!

I understand the obvious answer to my question is: "it depends". With that out of the way, I'm hoping one (or more) of you will help me see common ways to approach this...

I'm designing a database of widgets for sale. Over time the prices for each item will inevitably change. My question is should we be tracking these changes and if so, how? related table of pricing & dates? Is it common to track the change in price so you could, say, look back 3 years from now and see what changed and when. I could see how that could be valuable but is it worth the overhead?

The orders table will capture the current price on the date of the sale.

thoughts?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许一世地老天荒 2024-09-15 20:58:39

你的直觉是对的。如果可以的话,永远不要丢失信息!

使用 SQL Server 语法创建一个类似如下的表:

CREATE TABLE PriceHistory (
PK_PriceHistory int IDENTITY(1,1) PRIMARY KEY, 
FK_Item int, -- foreign key to your item table
Price money,
ChangedAt datetime  -- captured at the time of change
)

您可以通过价格(或商品?)表上的触发器填充该表,以便当价格更改时,您可以自动将旧价格记录到价格历史表中。这将允许您查询价格历史表以确定历史价格(如果需要)。我不喜欢触发器,但这是一个经典案例......

Your intuition is right on. Don't ever lose information if you can help it!

Create a table named something like this, using SQL Server syntax:

CREATE TABLE PriceHistory (
PK_PriceHistory int IDENTITY(1,1) PRIMARY KEY, 
FK_Item int, -- foreign key to your item table
Price money,
ChangedAt datetime  -- captured at the time of change
)

You can populate the table from a trigger on your Price (or Item?) table so that when a price is changed you can automatically log the old price to your price history table. This will allow you to query the price history table to determine an historical price if ever required. I'm not a fan of triggers but this is a classic case for one...

小猫一只 2024-09-15 20:58:39

补充塔巴扎的答案:

重要性不仅在于跟踪历史价格,还在于缓解未来的价格变化。如果没有“更改时间”,或者在这种情况下实际上没有“有效起始”日期来配合价格,您始终必须在应用价格的确切日期更改数据库中的价格。有了有效的起始日期,您就可以在您认为合适的时候输入新价格,并使其在您指定的日期成为“当前”价格。

Adding to Tahbaza's answer:

The importance isn't just in keeping track of historic prices, but also in easing price changes in the future. Without a "Changed At", or in this case actually a "Valid from" date to go with the price, you would always have to change the prices in the database on the exact day from which they should be applied. Having a valid from date allows you to enter new prices whenever you see fit and have them become the "current" price at the date you specified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文