简体   繁体   中英

One to many relationship in mysql

I Have the two tables User and Assets . The situation is as followed :

  • 1 assets to several users.

What should be my Database design ?

User

+---------+---------+
| UserId | Name     |
+---------+---------+

Assets

+---------+---------+
| AssetId | Name    |
+---------+---------+

User_asset_relation

+---------+---------+
| UserId  | AssetId |
+---------+---------+

What I think is that UserId and AssetId should have another table with foreign keys from the other two tables.

The design you described is actually many to many relationship. If each user is assigned only one asset, than you can add assetId column to users table. If one user can have multiple assets and same asset can be assigned to multiple users, than this is many to many relationship and your design is ok.

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