scenario


One type of field in a database table with a very high attendance rate is the status (status, state, etc.). I am currently designing a database table with two status values of the status field: “Normal” and “logout”. There are two common uses:

0: normal. 1: deregistered

0: logout. 1: normal

Some people use the first, some people use the second. Is there any difference?

  • Using the first method of maize, I don’t know about you.
  • Boolean type 0 means false, 1 means true, so 0 means logout, 1 means normal, logic is very strict and consistent.

The plot development


At this critical moment, several states are added to the system iteration process, such as: locked, expired, and shielded. Compare the two methods:

0: normal, 1: deregistered, 2: locked, 3: expired, 4: masked

0: logout, 1: normal, 2: locked, 3: expired, 4: masked

At this point, do you see a difference, do you find the first way more elegant? Why is that?

Because “happy families are all alike, each unhappy family is unhappy in its own way” 🤣

There is only one normal state represented by 0, and 1, 2, and 3 respectively represent different abnormal conditions. There is also a bonus: you can use status > 0 to retrieve all exception status.

nonsense


As a reminder, the field name is status and it has nothing to do with Boolean. If your field name is is_deleted, I think it would be logical for you to use 0 for not and 1 for yes.

The above is some of my nonsense, if you think there is some sense, I hope to help you, if there is something wrong, I hope to quarrel with you, haha, thank you!