Best way to save state flag in table (char or int)

I need to have a column called status in the table. this status column may contain → activated , expired , deactivated . so I wonder why I cannot create an integer column named status and store them as 0, 1, 2 (expired, activated, deactivated). but we are asked to use such things. CHAR instead of Int. so this will be the status of Char (2) and save as 0, 1, 2.

why should I use CHAR, since the column type instead of Integer is my question?

+4
source share
2 answers

For the field of the flag, I usually use CHAR (1), so I have a few important, but internal values, such as 'A', 'E', 'D'- I do not use the values of consecutive integers in that because they did not disclose the information!

These flag values ​​- even if yours are "more readable", are still displayed through constants, so that "magic values" do not appear in the code. (Unfortunately, they should still appear in Views and whatnot.)

Be careful when combining flags: if a flag tries to represent too much (for example, more than a small discrete set of values), then it is probably too complex and should be divided into several columns / relations.

+2
source

, StatusType, 10 (10, 20, 30...). , IsActive.

. , .

, , SQL SERVER - , . . , .

+1

All Articles