简体   繁体   English

删除产品后如何继续使用交易中的数据

[英]How can the data on the transaction still be used when the product has been deleted

enter image description here 在此处输入图片说明

I have a problem regarding transaction data in the reports of products that have been sold. 我对已售产品报告中的交易数据有疑问。 Constraints that occur if the product has entered the transaction / order but the product in question has been deleted. 如果产品已输入交易/订单但有问题的产品已被删除,则会发生约束。

How do I make the transaction report can still be used with the product that was deleted earlier? 如何使交易报告仍可与之前删除的产品一起使用?

Thanks. 谢谢。

Perhaps the best way to handle this possibility would be to add constraints to the tables involved which would make it not possible to delete a product row if an extant order exists which uses that product. 处理这种可能性的最佳方法可能是向所涉及的表中添加约束,如果存在使用该产品的现有订单,则无法删除该产品行。 Here is what the table definitions for Products and Order_Items might look like: 这是ProductsOrder_Items的表定义的样子:

CREATE TABLE Order_Items (
    order_item_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    order_id INT NOT NULL,
    product_id INT NOT NULL,
    ...
    FOREIGN KEY fk_prod (product_id) REFERENCES Products (product_id)
)

CREATE TABLE Products (
    product_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    product_name VARCHAR(255) NOT NULL,
    ...
)

With this design in place, should someone attempt to delete a product record from the Products table while there exists on or more order item records referring to that product, the delete attempt would fail. 采用这种设计后,如果有人尝试从“ Products表中删除产品记录,而同时存在一个或多个引用该产品的订单项记录,则删除尝试将失败。

If a row in the Products table is used for two things, namely for purchasing the product and for reporting on a historical transaction, then you can never actually delete the row. 如果“ Products表中的行用于两件事,即用于购买产品和报告历史交易,则您永远无法实际删除该行。

You might flag it in various ways: "available_for_purchase", "inventory = 0", "no_longer_produced", etc. 您可以通过多种方式标记它:“ available_for_purchase”,“库存= 0”,“ no_longer_produced”等。

暂无
暂无

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

相关问题 PHP,MySQL,PDO事务-在调用commit()之后可以使用rollBack()吗? - PHP, MySQL, PDO Transaction - Can rollBack() be used after commit() has been called? 从MySQL导入JOINed表时,数据已自动删除 - Data has been deleted automatically when importing JOINed tables from MySQL 如何确定何时将表单数据成功输入数据库? - How can I determine when the form data has been successfully entered in the database? 删除数据库中的条目并验证它是否已被删除 - 删除后仍然找到该条目 - Deleting an entry in database and verify that it has been deleted - still finding the entry after deleting it 我可以使用Selenium IDE测试是否已将事务添加到数据库吗? - Can I test that a transaction has been added to the database with Selenium IDE? 如何显示已从我的控制器添加的 DB 的最新/最后产品产品 - How can I show the latest/last product products that has been added DB from my controller 如何检查 email 是否已经使用 - How to check if the email has already been used 如何检查数据是否已成功插入? - How can I check data has been inserted successfully? 如何检测该事务已经开始? - How do detect that transaction has already been started? 如何避免“用于此报告的数据处理扩展名不可用。 它已被卸载,或者配置不正确” - How to avoid “The data processing extension used for this report is not available. It has either been uninstalled, or it is not configured correctly”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM