MySQL中许多布尔值的替代方案?
假设我有一个复选框搜索表单,如下所示:
let's say I have a checkbox search form like this:
检查您感兴趣的所有内容:
- 保龄球
- 台球
- 甜食
我可以从数据库中请求此数据,而不必像这样向数据库中添加大量布尔值吗?
Can I request this data from a database instead of having to resort adding tons of booleans to a database such as this?
(地点ID,IfBowling,IfBilliard,IfSweets)
(VenueId, IfBowling, IfBilliard, IfSweets)
也许只有一列包含场所本身具有的所有这些选项?
And maybe just have one column that would contain all of those options that the venue itself has?
替代..确定..容易:
Alternative .. sure .. easy :
User
表,Interests
表,UserInterests
表.
UserInterests
用于存储Users
和Interests
之间的多对多关系,并且包含上述表中FOREGN KEY
的值.
UserInterests
is used to store many-to-many relation between Users
and Interests
, and contains values which are FOREGN KEY
s from said tables.
P.S.您确实应该阅读 SQL Antipatterns 这本书.您将从中学到很多东西.
P.S. You really should read SQL Antipatterns book. You would learn a lot from it.