Database normalization design - single or multiple tables

后端 未结 7 1602
臣服心动
臣服心动 2021-01-14 15:28

Should this be represented in the database as 1 table or 3 tables? I and my friend have different opinions about this so I\'d like to see the general views on this. (Maybe

相关标签:
7条回答
  • 2021-01-14 16:24

    I would absolutely not go with the 3-table solution. By breaking this data into 3 tables, you really can't have any queries return a full order header without joining with the foreign key, and every insert of a new order updates multiple tables and indexes, which is a problem for concurrency. I would suggest using 2 tables, one for InternalOrders and one for ExternalOrders. For those cases where you need a consolidated query of data from both sets of orders, define a view that is the union of both tables.

    I am surprised to see product id and quantity as part of the order header. Every order tracking database I've ever seen breaks out order items as a separate table, using the order id as a foreign key, so that a single order can include multiple products (or the same product with various quantities, delivery times, etc.).

    0 讨论(0)
提交回复
热议问题