Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Drop Recreate then populate

Author  Topic 

emanresu
Starting Member

3 Posts

Posted - 2009-04-03 : 10:03:07
I have a table in which one of the columns is not sufficient. I need to insert a string into a varchar(50) column which exceeds 50 characters. This requires that I recreate the table because it contains data.

My question is how can I populate the new table with the information from my old table and still change the max length of the column?

I realize
SELECT * INTO X from Y
copies the entire table but that does not allow me to change the properties of the column. Thanks for the help.

(working in sql server 2008)

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-04-03 : 10:26:39
U Change the datatype of the column from varchar(50) to varchar(max)

Jai Krishna
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-03 : 10:26:43
you can use 'alter column' if compaitibilty level is set to later than 65. Or, you can copy the script of the existing table. Change the size of varchar column, change the name of the table and create a new table. Then you could do an insert instead of running a select INTO.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-03 : 10:29:28
syntax for alter column is,

 alter table tablename alter column columnname varchar(max)
Go to Top of Page
   

- Advertisement -