29

I can't find what the syntax looks like for adding a DATETIME column to a mysql table when I want to set the default to - example - 2011-01-26 14:30:00

Does anyone know what that syntax looks like?

Here's what I've got

ADD COLUMN new_date DATETIME AFTER preceding_col,

Thanks

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
H. Ferrence
  • 7,906
  • 31
  • 98
  • 161

2 Answers2

45

If you ever have doubts, the syntax is explained here http://dev.mysql.com/doc/refman/5.5/en/alter-table.html

ALTER TABLE yourTable 
  ADD COLUMN new_date DATETIME NOT NULL DEFAULT 20110126143000 AFTER preceding_col

or

ALTER TABLE yourTable 
  ADD COLUMN new_date DATETIME NOT NULL DEFAULT '2011-01-26 14:30:00' AFTER preceding_col

(I just prefer the numeric DATETIME format)

Mchl
  • 61,444
  • 9
  • 118
  • 120
12
ALTER TABLE  `yourTable`
ADD `new_date` DATETIME NOT NULL
DEFAULT '2011-01-26 14:30:00'
AFTER `preceding_col`
gen_Eric
  • 223,194
  • 41
  • 299
  • 337