美文网首页
MySQL中设置性别时想设置“男”,“女”,“保密”,而且要默认

MySQL中设置性别时想设置“男”,“女”,“保密”,而且要默认

作者: 呓兮 | 来源:发表于2017-09-16 17:18 被阅读1214次

比如在创建用户表的过程中,涉及到设置性别:

CREATE TABLE imooc_user(

id int unsigned auto_increment key,

username varchar(20) not null unique,

password char(32) not null,

sex enum('保密','男','女')not null,

face varchar(50) not null,

regTime int unsigned not null

);

(sex enum('男','女','保密')not null default '保密',)刚开始我一直是这样写的,于是一直报错。。。后来在网上看到,MySQL中enum类型的字段不能显式设置默认值,默认为第一个值,比如你写的‘男’。若要把默认设置成“保密”,可以把“保密”放在第一个位置。

于是问题就解决了!

转自本人博客:http://blog.163.com/qianshiguang_wa/blog/static/237777152201523134335388

相关文章

网友评论

      本文标题:MySQL中设置性别时想设置“男”,“女”,“保密”,而且要默认

      本文链接:https://www.haomeiwen.com/subject/qygvittx.html