What does the Alter Table syntax look like for adding a DATETIME column?

前端 未结 2 968
你的背包
你的背包 2021-02-18 14:11

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

相关标签:
2条回答
  • 2021-02-18 14:22

    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)

    0 讨论(0)
  • 2021-02-18 14:32
    ALTER TABLE  `yourTable`
    ADD `new_date` DATETIME NOT NULL
    DEFAULT '2011-01-26 14:30:00'
    AFTER `preceding_col`
    
    0 讨论(0)
提交回复
热议问题