Can a field with DATE type have a DEFAULT value wi

2019-09-13 22:15发布

I know that for a DATETIME column you can you CURRENT_TIMESTAMP but what about a DATE column? I don't need hours, minutes and seconds and while trying to set CURRENT_TIMSTAMP as default for I get an error. Thanks

2条回答
Emotional °昔
2楼-- · 2019-09-13 22:43

A date or time type columns can be defined with a default 0 but not a curdate() or curtime().

As per documentation on Data Type Default Values:

The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE.

查看更多
叛逆
3楼-- · 2019-09-13 22:58
on update CURDATE();   

Try this if it works

ALTER TABLE `tablename` 
   CHANGE `tablename` `tablename`timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
查看更多
登录 后发表回答