MySQL 添加 DATETIME 列的 Alter Table 语法是什么样的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4810066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the Alter Table syntax look like for adding a DATETIME column?
提问by H. Ferrence
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
当我想将默认值设置为 - 示例 - 2011-01-26 14:30:00 时,我找不到将 DATETIME 列添加到 mysql 表的语法是什么样的
Does anyone know what that syntax looks like?
有谁知道那个语法是什么样的?
Here's what I've got
这是我所拥有的
ADD COLUMN new_date DATETIME AFTER preceding_col,
Thanks
谢谢
回答by Mchl
If you ever have doubts, the syntax is explained here http://dev.mysql.com/doc/refman/5.5/en/alter-table.html
如果您有疑问,请在此处解释语法 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)
(我只是更喜欢数字 DATETIME 格式)
回答by Rocket Hazmat
ALTER TABLE `yourTable`
ADD `new_date` DATETIME NOT NULL
DEFAULT '2011-01-26 14:30:00'
AFTER `preceding_col`