修改 int 为 float (mysql)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15859487/
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 17:14:19 来源:igfitidea点击:
modify int to float (mysql)
提问by Yevgen
I'm trying to change datatype from INT to FLOAT in MySQL like this:
我正在尝试将 MySQL 中的数据类型从 INT 更改为 FLOAT,如下所示:
ALTER TABLE user MODIFY rate float(5) NOT NULL
But current data is droped. Is there any way to convent\save data from INT to FLOAT with SQL?
但当前数据被丢弃。有什么方法可以使用 SQL 将数据从 INT 保存到 FLOAT 吗?
回答by Fran García
I have just tried
我刚试过
ALTER TABLE user MODIFY rate float(5) NOT NULL
with mysql 5.6.26 and it worked without dropping the value.
使用 mysql 5.6.26 并且它在不降低值的情况下工作。
回答by Yevgen
ALTER TABLE `user` CHANGE rate intrate INTEGER;
ALTER TABLE `user` ADD rate float(5) NOT NULL DEFAULT 100;
UPDATE `user` SET rate=intrate;
ALTER TABLE `user` DROP intrate;