mysql中使用bigint保存时间

MySql 码拜 8年前 (2016-02-05) 2885次浏览
在mysql数据库中,本人有一个user表,本人想添加一列regist_time,用来记录用户注册的时间。类型为bigint(20),默认值为当前日期对应的毫秒值或秒值。下面是本人的sql语句
mysql> alter table user add column regist_time bigint(20) not null now()+0  after age;
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 “now()+0  after age” at line 1.
其中now+0换成 now()/unix_timestamp(now())/now().getTime()都不行,都是报同样的错误。问一下是什么原因,正确的sql语句应该怎么写。
谢谢!
解决方案

40

mysql 中默认值是不支持函数的,只能通过触发器来实现。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明mysql中使用bigint保存时间
喜欢 (2)
[1034331897@qq.com]
分享 (0)