简体   繁体   中英

Optimization of the structure and database MySQL

I have the following relationships:

order_products (1 or n) ———————— (1) orders (1) ————————— (1) transactions
    ...                                (1)                         (1)
    price                               |                           |   
    qty                                 |                           |
                                       (1)                         (1)
                                      users                       users
  1. Should I leave 2 relationships to users table as above?
  2. I intend to show the total order amount or get the transaction amount will query the order_products table. This is better than adding the amount field at 1 of two tables (or both) orders, transactions?.

Start by deciding which relationship exists in each case:

  • 1-1 -- the two tables should probably be merged together.
  • 1:many -- the "many" table has a column with the ids into the "one" table.
  • many:many -- This needs an extra table with 2 ids (one for each table).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM