All Forums Database
Kbos 20 posts Joined 04/13
05 Jun 2013
About renaming a column

Hi everyone
 
I've created a table and I want to modify the datatype to one field from Char(4) to Char(5) but it is not possible....I tried to rename the column using the following statement and it was executed OK.

ALTER TABLE Table2
RENAME Desc_Catalog as Desc_Catalog_Tm,  ADD Desc_Catalog CHAR(5) 

and I've realized that the new field which is Desc_Catalog (which has the new datatype) does not contain any information at all. Is there any way that once the rename has been done the new field contain the data? I dont want to create a temporary table and once it has been created, pass the data from the temporary table to the new one.
 
Thanks in advance

Harpreet Singh 101 posts Joined 10/11
05 Jun 2013

Hi,
that correct that you have renamed the column so Desc_Catalog_Tm contains data now and Desc_Catalog is empty. You cannot modify column datatype. You can add below statement after alter as you dont want temp tables
update table2 set Desc_Catalog= Desc_Catalog_Tm
thanks

05 Jun 2013

Hello Kbos,
Your syntax is also working fine at my end.
I could rename column name with data using your synax.
Regards,
Chinmay

Kbos 20 posts Joined 04/13
06 Jun 2013

Thanks Harpreet for your suggestion :)
Thanks Chinmay :)

You must sign in to leave a comment.