I'm a beginner in MySQL, and I accidentally created a table with a column named
(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?
Just put decimal(precision, scale) , replacing the precision and scale with your desired values.
It has a range of 1 to 65. D is the number of digits to the right of the decimal point (the scale).
The ROUND() function rounds a number to a specified number of decimal places.
ALTER TABLE mytable MODIFY COLUMN mycolumn newtype
example:
ALTER TABLE YourTableNameHere MODIFY COLUMN YourColumnNameHere decimal(4,2)
Just ALTER TABLE
with the MODIFY
command:
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With