Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the data type for a column in MySQL?

Tags:

mysql

I want to change the data type of multiple columns from float to int. What is the simplest way to do this?

There is no data to worry about, yet.

like image 770
Eric Wilson Avatar asked Aug 31 '09 10:08

Eric Wilson


People also ask

How do I change the datatype of a column in SQL?

To modify the data type of a column Select the column for which you want to modify the data type. In the Column Properties tab, select the grid cell for the Data Type property and choose a new data type from the drop-down list. On the File menu, select Save table name.

How do I change the properties of a column in MySQL?

To change a column's definition, use MODIFY or CHANGE clause along with the ALTER command. mysql> ALTER TABLE testalter_tbl MODIFY c CHAR(10); With CHANGE, the syntax is a bit different. After the CHANGE keyword, you name the column you want to change, then specify the new definition, which includes the new name.

What command is used to change the data type of a column?

The ALTER COLUMN command is used to change the data type of a column in a table.


2 Answers

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

ALTER TABLE tablename MODIFY columnname INTEGER; 

This will change the datatype of given column

Depending on how many columns you wish to modify it might be best to generate a script, or use some kind of mysql client GUI

like image 185
Yannick Motton Avatar answered Sep 21 '22 02:09

Yannick Motton


alter table table_name modify column_name int(5) 
like image 42
php Avatar answered Sep 21 '22 02:09

php