Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Column in MySQL from int to double?

Basically, I currently have a column in a MySQL table, which is an int.

I'd like to change that to double. I've searched the web, but all it came up with was conversion upon getting the values from the column (like converting some date to Date), but that's not what I mean.

I'm guessing it's something with Alter Table, and I looked that up on the MySQL dev page, but could not find what I was looking for.

like image 681
Lolmewn Avatar asked Apr 25 '12 19:04

Lolmewn


2 Answers

Here's the real syntax. Make sure to set the nullability appropriately too:

ALTER TABLE your_table
MODIFY COLUMN your_column DOUBLE NULL;

or

ALTER TABLE your_table
MODIFY COLUMN your_column DOUBLE NOT NULL;
like image 150
Ike Walker Avatar answered Sep 21 '22 16:09

Ike Walker


You're right that you need to use ALTER TABLE. The command will look something like this:

ALTER TABLE tablename MODIFY COLUMN columnname DOUBLE;
like image 43
eggyal Avatar answered Sep 23 '22 16:09

eggyal