I am creating a shopping cart and an currently planning / building the checkout process. Everywhere I look I see the recommendation to have an order table, and in that order table have a productId for the product that is being ordered… That seems nice. But I can not seem to get over the issue of what happens of that product is updated or worse deleted? Then the record of what is ordered is updated or deleted. Would it be better to duplicate the product details into an OrderedProduct table so you have a snapshot of what the product looked like when it was ordered? Then even if the product is changed or deleted, you have all the information from when it was ordered? That is what I am doing, but want to make sure I am not making a mistake or there is a better way to accomplish it.
Mysql – Shopping cart database, should order object have a relationship with the product, or should I duplicate the product information
MySQL
Related Question
- Mysql – Avoiding Multiple Queries when Searching for Records Associated with a Set of Records
- Mysql – Order table Database design
- Mysql – Shopping cart schema with multiple product tables
- Mysql – Query or a New Column for Performance
- Mysql – Is it advisable to asynchronously update the summary table every time a transaction is deleted
- MySQL Database Design – How to Design a Website Database Structure
- Mysql – Primary key advice for simple table
Best Answer
If the item changes or gets updated, it should get a new ItemID. You need the historic record. So say you have a shirt and it comes in blue ItemID Shirt. If you offer it in Green change the new ItemId to be ShirtGreen. iF it is an upgrade, say offering blue shirt with a pointed collar: ItemID: ShirtPointedCollar.