环境 mysql 5.1 命令行工具 问题 mysql表字段设置默认 解决 --sql:create table test( i_a int not null default 1, ts_b timestamp not null default now(), c_c char(2) not null default '1');--以下sql不合法--time_d time not null default curtime(),
环境mysql 5.1 + 命令行工具
问题mysql表字段设置默认值
解决--sql:create table test( i_a int not null default 1, ts_b timestamp not null default now(), c_c char(2) not null default '1');--以下sql不合法--time_d time not null default curtime(),--date_e date not null default curdate(),--datetime_f datetime not null default now(),
总结int类型:默认值也得是整型,并且default后边不要()括号。
char类型:默认值使用单引号。
datetime类型:now()函数以'yyyy-mm-dd hh:mm:ss'返回当前的日期时间,可以直接存到datetime字段中。不支持使用系统默认值。
date类型:curdate()以'yyyy-mm-dd'的格式返回今天的日期,可以直接存到date字段中。不支持使用系统默认值。
time类型:curtime()以'hh:mm:ss'的格式返回当前的时间,可以直接存到time字段中。不支持使用系统默认值。
参考资料
mysql表字段默认值
http://zhidao.baidu.com/question/161654544.html
mysql获取系统当前时间的函数
http://blog.csdn.net/wentasy/article/details/7846679
@wentasy