I have a mysql table with my users… each user has various attributes like Verified(yes/no), Member (yes/no) etc.. i dont need to explain more..is a very common case…
i’ve been alwasy using to build my tables with single rows like this, maybe for lazyness or just because i never built big DB so far…
userId | userName | Verified | Member
---------------------------------------
3213 | Jon | 1 | 0
but i wonder if there is any advantages to build it into separate tables, and create relationships later, like
User Table
userId | userName |
-------------------
3213 | Jon |
Memberships table
memberId | userId | Member |
--------------------------------
555748 | 3213 | 0 |
Verifications Table
memberId | userId | Verified |
----------------------------------
555748 | 3213 | 1 |
what is the real benefit from this second choice?
There’s no real advantage here, only disadvantages. There is a 1:1 relationship between the tables, and now you have to join the two tables to get the verification state of a user. Also, there are more possible cases now: a user can be verified (1) unverified (0) or the record might not exist.
You can better put these extra fields in the same table, unless there’s a 1 to many relationship. For example, a user can have posts, friends, pictures, which you store in a separate table because you don’t know how many you need to save.