您的位置:首页 > 产品设计 > UI/UE

mysql boolean类型default 0/1 not true,false

2011-10-31 21:47 148 查看
You have to specify 0 (meaning false) or 1 (meaning true) as the default. Here is an example:

create table mytable (

mybool boolean not null default 0

);

FYI: boolean is an alias for tinyint(1).

mysql> create table mytable (

-> mybool boolean not null default 0

-> );

Query OK, 0 rows affected (0.35 sec)

mysql> insert into mytable () values ();

Query OK, 1 row affected (0.00 sec)

mysql> select * from mytable;

+--------+

| mybool |

+--------+

| 0 |

+--------+

1 row in set (0.00 sec)

FYI: My test was done on the following version of MySQL:

mysql> select version();

+----------------+

| version() |

+----------------+

| 5.0.18-max-log |

+----------------+

1 row in set (0.00 sec)

在mysql中设置字段类型为boolean。mysql会自动变成tinyint(1)。明白了为什么default value 为0/1。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: