MySQL SQL Query 0 or 1
I have a very simple question. I have an SQL query that looks like this:
CREATE TABLE `users` (
[...]
`开发者_运维百科ABC` BIT()
[...]
)
I want ABC
to be either 0
or 1
I am just wondering, is this the correct way to do it?
Drop the ()
:
CREATE TABLE `users` (
[...]
`ABC` BIT,
[...]
)
Like most people, I usually pick TINYINT(1)
over BIT
, but I think this is fine.
The issue with MySQL is that it doesn't have a real Boolean data type, and neither TINYINT
nor BIT
can represent a column that holds exactly two non-NULL
values of 0
and 1
(they have different ranges of values). The only way is to emulate it with a really small numeric column and pray nobody sneaks in non-zero-or-one values...
Bit
has some oddities that go along with it in new version of MySQL. I'd suggest using a bool
or tinyint(1)
.
精彩评论