简体   繁体   中英

Database Schema - MYSQL and PHP

I am a newbie with creating a robust database system. But after completing, my challenge lies with two table, User table and Category table . Each user in the database must create categories for their products. Initially, i made it a many to many relation (creating a pivot table user_category table ) but now, i having doubts.

Can i still use the many to many relationship for the user and category table?

If 2 or more users can have the same categories I would recommend to use this structure:

user table:
|user_id|user_name|...

categories table:
|category_id|category_name|...

user_categories table:
|user_id|category_id|

If a category is unique per user I would add the user_id column in the category table

user table:
|user_id|user_name|...

categories table:
|category_id|category_name|user_id|...

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