简体   繁体   中英

create mysql table with one to many relationship

I already created two tables say users and files . The users table has fields: user-id, username . The files table has fields: file-id, file-name and user-id.

If I use this relation then we have one file item pointing to only one customer. I want to use an array of users in the files table. How do I store it in table?

You'll need another table users_files with fields user-id, file-id to store that

Then you can insert as many users as you want for each file.

Use foreign keys to maintain integrity check

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