MySQL values ​​are limited to 1 and 0

Hi guys, I'm just a beginner, so sorry for my question :)

I already tried using char, tinyint, bool and CHECK constraints.

Here is my CHECK constraint:

CHECK (user_type>=0 AND user_type<=1)

But still I can insert values ​​greater than 1, all I want is just 1 s and 0. I will use it as the type of my users. Although I can test this at the front-end level, I still want to do this in the database itself.

Thanks in advance:)

+3
source share
4 answers

use setor enumas a colum type. then define the values ​​(ex: 1.0) :)

+4
source

The CHECK clause is parsed but ignored by all storage engines. (Source)

, , 0 1, .

+3

If you really want this restriction to be enforced, make the boolconstants table with these two values ​​and use the foreign key constraint. Hack bit, but works for all enum values ​​:)

0
source

Since this is MySQL, will the enumeration column force the restriction as expected?

http://dev.mysql.com/doc/refman/5.0/en/enum.html

0
source

Source: https://habr.com/ru/post/1759680/


All Articles