简体   繁体   English

数据库架构-MYSQL和PHP

[英]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 . 但是完成之后,我的挑战在于两个表,即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. 最初,我建立了多对多关系(创建数据透视表user_category table ),但是现在,我user_category table表示怀疑。

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: 如果2个或更多用户可以具有相同的类别,我建议使用此结构:

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_id

user table:
|user_id|user_name|...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM