MySQL 如何更改时间戳以默认设置为当前时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5501361/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:21:51 来源:igfitidea点击:
How do I alter a timestamp to set by default to the current time?
提问by david99world
The code below doesn't seem to work even though the collumn and table does exist, any ideas?
即使列和表确实存在,下面的代码似乎也不起作用,有什么想法吗?
ALTER TABLE `table` CHANGE 'collumn_1' 'collumn_1' TIMESTAMP DEFAULT 'CURRENT_TIMESTAMP' NOT NULL
I'm just trying to make the collumn available so it can store the current date and time when any data is added to this table.
我只是想使列可用,以便它可以在将任何数据添加到此表时存储当前日期和时间。
回答by Quassnoi
ALTER TABLE `table` MODIFY collumn_1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;