How should the order table of mysql database be designed to be more reasonable?

there are two table-building schemes that I have come up with:

first:
order_id order id
shop_id merchant id
goods_id goods id
.
this way is to write all kinds of id in the order table and associate them when needed.

second:
order_id order id
shop_name merchant name
goods_name purchased item name
price unit price
total total price
.
this method is like a handwritten ledger, which writes the account data directly in the table.

what are the advantages and disadvantages of these two? In general, how should the order form be designed?


depending on your business, there is no good or bad.

  1. first, put all kinds of id on the order table, which is bound to make you conform to the third normal form when you need to query, but various cascading tables lead to inefficient SQL query
  2. second, the most basic information is extracted according to the actual business needs, and appropriate redundant fields are allowed in the table.

personally, I think the second possibility is better than the first.


that is of course the second kind of good.
your first query has to join three tables, which is troublesome both in efficiency and maintenance (feel very academic and elegant when writing, and ask for trouble when something goes wrong or performance tuning. Don't be too obsessed with paradigm requirements.


is determined according to business requirements, and appropriate redundancy important fields to the order table is necessary.

Menu