开发者

How to set default date time as system date time in mysql

开发者 https://www.devze.com 2022-12-25 10:54 出处:网络
I am trying to set my columns default date time to system datetime. It shows me an error Invalid default value for

I am trying to set my columns default date time to system datetime. It shows me an error

Invalid default value for 'InsertionDate'

alter table `vts`.`tblpickpoint` 
  add column `InsertionDate` 
      datetime DEFAULT 'No开发者_如何学JAVAw()' NULL after `PickPointLatLong`


The default value for a column in mysql cannot be the result of a function.

The one exception is the current_timestamp as astander points out.

Your statement should be

alter table `vts`.`tblpickpoint` 
  add column `InsertionDate` TIMESTAMP 
             DEFAULT CURRENT_TIMESTAMP 


Have a look at CURRENT_TIMESTAMP


If you want to init and update the value on every change, use this:

alter table `vts`.`tblpickpoint` 
  add column `InsertionDate` 
       TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  after `PickPointLatLong`

If you only want the creation time, use this:

alter table `vts`.`tblpickpoint` 
  add column `InsertionDate` 
       TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  after `PickPointLatLong`
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号