我想在 mysql 数据库中存储项目的类别。我应该为这个字段使用什么数据类型。请注意,一项可以有多个类别。一种快速(肮脏?不确定)的方法是按位使用 INT。但是INT是32位长,这意味着我最多只能为一个项目分配32个类别。目前来说,这不是问题。但我不知道如果有一天我必须这样做的话该怎么办。有什么建议吗?
最佳答案
类似的事情
table item
field item_id (int) => PK
item_name
etc
table category
field cat_id (int) => PK
field cat_name
etc
//a table to manage many to many relationship
table item_category
field item_id (int) => FK to item.item_id
field cat_id (int) => FK to category.cat_id
//PK is item_id, cat_id
关于mysql - mysql中的多类别字段应该使用什么类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16687161/