What is the best way to store trivial user states (e.g. declined greetings) in a database?

Should I use (create) a column for each new state? Or a single field with a bunch of comma-separated states (alternatively json obj)? Any suggestions are welcome.

UPDATE

First let me thank you for the answers. I just want to clarify which options I see:

  • Place a column for each state in the user row (initial plan) / May become messy with many states (in the future)
  • Put one column with json / xml data in user line / Easy to maintain (no need to change db), but it does not feel good.
  • There is a table of special states (thanks lhiles ) / Sounds great, what would this table look like?

I am looking for the pros and cons of various implementations. Again: Thank you!

+3
source share
4 answers

Create a column for each state. This is the correct normalization of data.

With a column for each state, you can get as few or as few states necessary for the current operation as possible.

All returned states will be contained on the same row with each column. This makes the reference to each state value very simple.

This allows you to easily add restrictions for each state as needed. (State X can only contain "1" or "2".)

. ( "X"?)

+2

- . / . .

, , , 1 , XML ( json, ) SQL. , , , .

0

ENUM, ; - .
SET, ; (AA CA SOsA *)

:

CREATE TABLE test.table1(
  test_enum ENUM('male', 'female') DEFAULT 'male',
  test_set SET('AA', 'CA', 'SOsA') DEFAULT NULL
)
ENGINE = INNODB;

ENUM, , null, .

: http://dev.mysql.com/doc/refman/5.1/en/constraint-enum.html

* ( , stackoverflow)

0

, . , ( ) , .

, , ( , ).

- , . , , . 10 .

CodeProject, .

0

All Articles