简体   繁体   中英

Database modeling in MySQL Workbench for order system

I'm trying to model a simple order system in MySQL Workbench and i'm having a few problems when it comes to normalization. Right now, i'm using WHERE id = x, another_id = x and so on to build a query. My system is rather simple:

  • User table
  • Order table
  • UserOrder table
  • Product table

An user has many orders and an order has many products. And that's about it. How can one define such relations in the MySQL workbench? Are there any tutorials on HasMany, HasOne and other kinds of relationships?

在此输入图像描述

For the most part your setup is okay. However, you don't need mapping tables for one-to-many mappings. For instance, it's highly unlikely that a single order can belong to multiple users and that an order item can belong to multiple orders. This means that your tables should be:

  • Users (userid)
  • Orders (orderid, userid)
  • OrdersItems (oiid, orderid, productid)
  • Products (productid)

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