将 mySQL 列数据类型从文本更改为时间戳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4611965/
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
Change a mySQL Column datatype from text to timestamp
提问by Deepank Gupta
How can I change the datatype of a column from text to timestamp. The current text column is storing dates in the format : '2010-08-15' (yyyy-mm-dd sql format)
如何将列的数据类型从文本更改为时间戳。当前文本列以以下格式存储日期:'2010-08-15'(yyyy-mm-dd sql 格式)
回答by mechanical_meat
ALTER TABLE `mydb`.`mytable` MODIFY COLUMN `mycol` TIMESTAMP;
Using the above command a value such as:
使用上面的命令一个值,如:
'2010-08-15'
will change to
将更改为
TIMESTAMP '2010-08-15 00:00:00'
回答by Nishant
Have you tried this
你有没有试过这个
alter table table_name change field_name field_name timestamp;
where table_name
is the name of the table and field_name
is the name of the field that you wanted alter the type of.
其中table_name
是表field_name
的名称,是要更改其类型的字段的名称。