简体   繁体   中英

Best approach to add multiple data to a colmun in MySQL

For exemple: I have 'Users' table and a 'Projects' table Multiple users can be members of a project. How do I insert multiple users into the "members" colomun of the Projects table?

Do I separate by comma like: "John, Alex, Hanna"?

I'm a begginner into MySQL, sorry if this is a dumb question. Thanks!

You defiantly need another table. It should look like this

Name: UserProjects

Field: UserId

Field ProjectID

Those 2 fields should be primary keys (dual primary id). If you want to go down the route of 'soft deletes' then add a status column which you'll set to 0 if you delete it. Also look up insert on update for mysql.

Trust me this is the way to go. Using a delimiter field or something will only give you problems later down the line.

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