5

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 'Now()' NULL after `PickPointLatLong`
OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286

3 Answers3

3

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 
lexu
  • 8,766
  • 5
  • 45
  • 63
2

Have a look at CURRENT_TIMESTAMP

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
0

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`
kaiz.net
  • 1,984
  • 3
  • 23
  • 31