Thursday, July 14, 2011

Change the Table Column Datatype with data using SQL

Follow the simple steps to change the column datatype which is also having a data inside.
Normally, it’s not possible to change the column datatype with the existing data.
Steps:
1. Add New temp Column with desired datatype.
SQL> Alter Table
Add temp datatype(size);

2. Update the data into new column.
SQL> Update
set temp =
where is not null;

3. Drop the original Column.
SQL> Alter table
Drop column ;

4. Rename the new column to original Name.
SQL> Alter table
rename column temp to ;


Note:- change the table_name, datatype, Original_columnname and size

No comments: