To Convert datatype for a column

HI 

I am using SQL server 2008 .I have a table which has 1.5 crore records and some of my columns are Char datatype.

Because of this i have spaces in my columns.Now I want to convert char to varchar datatype .But i have index on those columns .PLease tell me an efficient way to do this.

NOte:PLease remeber that in my table we have  1.5 crore records .ANd i don't have much down time

May 29th, 2015 2:20am

You need to drop the index and then run ALTER TABLE. Changing from char to varchar requires changing the page structure; that is SQL Server must rebuild the table.

An alternative is to add a new column and copy over data, while the table is still live. If the column is updated, all you need to consider are new rows that are added while you are working. Once the column is populated, you need to take the table offline to drop the old column and rename the one, but that is a swift operation.

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 3:26am

Thanks dude
May 29th, 2015 3:47am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics