MySQL数据库中给DateTime类型赋默认值问题,是不是用getdate()

SQL建表语句:
CREATE TABLE `Users` (
`UserID` int NOT NULL AUTO_INCREMENT ,
`UserName` varchar(50) NOT NULL ,
`PassWord` varchar(50) NOT NULL ,
`Created` datetime NOT NULL DEFAULT 'getdate()' ,
`Type` int NOT NULL DEFAULT 0 ,
PRIMARY KEY (`UserID`)
);
提示错误:#1067 - Invalid default value for 'Created'
求高人解答啊,急急急!!!

MySQL 中,默认值无法使用函数
也就是你无法 设置某一列,默认值是 NOW () 这样的处理

假如需要 某列的默认值为 当前数据库时间,那么可以使用 TIMESTAMP 数据类型。插入的时候,填写 null 即可。

mysql> create table testA ( dt TIMESTAMP );
Query OK, 0 rows affected (0.09 sec)

mysql> insert into testA VALUES( null );
Query OK, 1 row affected (0.01 sec)

mysql> insert into testA VALUES( null );
Query OK, 1 row affected (0.08 sec)

mysql> select * from testA;
+---------------------+
| dt |
+---------------------+
| 2011-10-15 20:30:35 |
| 2011-10-15 20:30:36 |
+---------------------+
2 rows in set (0.00 sec)
温馨提示:答案为网友推荐,仅供参考
相似回答