Database optimization orders

前端 未结 4 543
心在旅途
心在旅途 2020-11-29 14:01

In a database where users can place orders, is it better to have a new table with addresses or each order has the address data in its header.

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 14:47

    Don't reinvent the wheel. Order systems have been around for ages and best practices are well established. You can create an address book so that your contacts can have multiple addresses. Contact has zero-to-many Addresses. However, when it comes time to ship, do persist a copy of the address with the Order (or Shipment entity). It's important to store the address as point-in-time data in the order to maintain accurate historical data. Magento, Shopify, Quickbooks all the major accounting and eCommerce systems have a model like this. One exception is Saasu accounting. They do not persist the address with the order, so you have to create a new contact for each order, otherwise if you ever modify a customer address, you end up re-writing the address on historical orders. A really terrible design!

提交回复
热议问题