Changing The Datatype of a column

db , sql server India
  • 13 years ago

    Hi,,

     

    How to change the datatype of a particular column in an existing table in Sql-Server thro coding... ie i want to do it in query analyser..I have Sql -Server 2005 in my System.My table has data in it..

    Thanks in Advance..

  • 13 years ago

    It is possible... you simply use the "alter table" statement. However, you'd better double check that the column type alteration is allowed (ie castable) as it'll error out if its not- Sql Books Online should have this info.

    If this is not the case, you'll probably have to write a 'custom' routine that'll (a) extract all the data (b) change the column type and then (c) load the data back into the table with a customised column conversion function... Best to make a backup of the database in either case, just in case something happens. I've been caught out be this one on a previous occassion - one which I wouldn't like to have to redo ever again. Misery.

    Joe 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic