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

强颜欢笑 提交于 2020-08-22 07:40:49

问题


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


回答1:


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)




回答2:


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


来源:https://stackoverflow.com/questions/4810066/what-does-the-alter-table-syntax-look-like-for-adding-a-datetime-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!