简体   繁体   English

数据库设计问题:历史记录一致性

[英]Database design issue: History consistency

I don't know what is the term it used to define this problem, let me explain here with a simple example. 我不知道它用来定义此问题的用语是什么,让我在这里用一个简单的例子进行解释。 I have a products and orders table, with orders having one to many relationship with ordered_products table. 我有一个productsorders表,其中ordersordered_products表具有一对多关系。

See the tables:- 见表:-

products(id, sku, name, summary, price);

orders(id, code, customer_name, customer_address);
ordered_products(id, order_id, product_id, quantity);

Once the orders are generated, the ordered products are listed in the ordered_products table. 生成订单后,订购的产品将列在ordered_products表中。 The application then generates an invoice at that instance taking the price reference from the products table. 然后,该应用程序将在该实例处生成一张发票,并从products表中获取价格参考。 Problem occurs! 发生问题! when the product that has been ordered get edited. 当订购的产品得到编辑时。 For example if name or price is edited on the products table, the orders is affected creating a mismatch in actual orders. 例如,如果在products表上编辑了名称或价格,则订单会受到影响,从而导致实际订单不匹配。 What's the solution here? 这里有什么解决方案? Do I need to copy the values in the ordered_items rather than using a foreign key reference here? 我是否需要复制ordered_items的值,而不是在此处使用外键引用?

订单通常以约定的价格下单,因此下订单后更改产品价格确实意味着您必须将ordered_price存储在ordere_products表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM