Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify an existing column's data type?

One of the columns in a somewhat large table (~10,000 records) is of the data type DECIMAL(10,0). I'm using MySQL.

I'd like the values to be displayed to 2 decimal places, so I need to alter this to DECIMAL(10,2), without screwing up the table's existing records. How could this be done?

like image 434
oxo Avatar asked Nov 29 '11 05:11

oxo


People also ask

Is it possible to change a column's data type with records in SQL?

You can modify the data type of a column in SQL Server by using SQL Server Management Studio or Transact-SQL. Modifying the data type of a column that already contains data can result in the permanent loss of data when the existing data is converted to the new type.

How do you modify data type?

Change data types in Datasheet view Access opens the table in Datasheet view. Select the field (the column) that you want to change. On the Fields tab, in the Properties group, click the arrow in the drop-down list next to Data Type, and then select a data type. Save your changes.

Which syntax will modify the data type of an already existing column?

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.


1 Answers

Which DBMS are you using ? you can try like this for MySQL :

alter table tblName modify columnName newDataType;
like image 91
gprathour Avatar answered Oct 07 '22 02:10

gprathour