首页 新闻 会员 周边

为何我在Mysql中创建表格,无法使用curdate()作为日期的默认值?

0
[已解决问题] 解决于 2014-11-05 09:46

想创建一个表格a,有两个字段id,dateGo;

id是主键,自增,无符号类型;

dateGo是日期类型,想使用当前日期作为默认值。

但是创建的时候无法成功,请问是哪里出错了呢?

mysql> create table a (id int unsigned not null primary key auto_increment, dateGo date not null default curdate());
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'curdate())' at line 1

Charlie123的主页 Charlie123 | 初学一级 | 园豆:142
提问于:2014-11-04 10:42
< >
分享
最佳答案
0

试试这个:CREATE TABLE a (id int unsigned not null primary key auto_increment, dateGo timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)

奖励园豆:5
gltide | 菜鸟二级 |园豆:403 | 2014-11-04 11:26

使用这一句成功了。

不过带着时分秒,我想就要日期,不要时分秒。这样可以做到么?

Charlie123 | 园豆:142 (初学一级) | 2014-11-04 12:07

@Charlie123: 本人的机器没有mysql,试试这个:create table a (id int unsigned not null primary key auto_increment, dateGo timestamp not null default curdate());

gltide | 园豆:403 (菜鸟二级) | 2014-11-05 09:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册