开发者

Alternative to lots of booleans in MySQL?

开发者 https://www.devze.com 2023-03-31 08:49 出处:网络
let\'s say I have a checkbox search form like this: Check all that interests you: bowling billiard sweets

let's say I have a checkbox search form like this:

Check all that interests you:

  • bowling
  • billiard
  • sweets

Can I request this data from a database instead of having to resort adding tons of booleans to a database such as this?

(VenueId, IfBowling, IfBilliard, IfSweets)

And may开发者_开发技巧be just have one column that would contain all of those options that the venue itself has?


Alternative .. sure .. easy :

User table, Interests table, UserInterests table.

UserInterests is used to store many-to-many relation between Users and Interests, and contains values which are FOREGN KEYs from said tables.

P.S. You really should read SQL Antipatterns book. You would learn a lot from it.

0

精彩评论

暂无评论...
验证码 换一张
取 消