MySQL - 如何更新小数列以允许更多数字?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19773164/
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
MySQL - How do I update the decimal column to allow more digits?
提问by ValleyDigital
I'm a beginner in MySQL, and I accidentally created a table with a column named
我是 MySQL 的初学者,我不小心创建了一个表,其中有一列名为
(price decimal(2,2));
It needs to be decimal(4,2)
to allow 4 digits. Since I've already created it, what is the easiest way to update that decimal value to decimal(4,2)
? Or do I need to drop that column completely, and re-create it with the correct numbers?
它需要decimal(4,2)
允许4位数字。由于我已经创建了它,将十进制值更新为 的最简单方法是什么decimal(4,2)
?或者我是否需要完全删除该列,并使用正确的数字重新创建它?
回答by Eduardo Dennis
ALTER TABLE mytable MODIFY COLUMN mycolumn newtype
example:
例子:
ALTER TABLE YourTableNameHere MODIFY COLUMN YourColumnNameHere decimal(4,2)
回答by h2ooooooo
Just ALTER TABLE
with the MODIFY
command:
只需ALTER TABLE
使用以下MODIFY
命令:
ALTER TABLE `table` MODIFY `price` DECIMAL(4,2)
This would allow for 2 decimals and 2 full numbers (up to 99.99
). If you want 4 full numbers, use 6,2
instead (which would allow up to 9999.99
).
这将允许 2 个小数和 2 个完整数字(最多99.99
)。如果您想要 4 个完整数字,请6,2
改用(最多允许9999.99
)。
回答by Filipe Silva
It's not a matter of 'UPDATE' it's a matter of changing your table's structure. For that, use ALTER TABLEwith MODIFY
clause:
这不是“更新”的问题,而是更改表结构的问题。为此,将ALTER TABLE与MODIFY
子句一起使用:
ALTER TABLE YourTableName MODIFY COLUMN price DECIMAL(4,2);
回答by denny
use CHANGE
使用更改
ALTER TABLE table_name CHANGE OLD_COLUMN_NAME OLD_COLUMN_NAME datatype;
an example
一个例子
ALTER TABLE table_name CHANGE price price decimal(4,2);