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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 updating table

Author  Topic 

Sean_B
Posting Yak Master

111 Posts

Posted - 2009-06-09 : 09:46:07
Hi,

I'm running the following code to change a column from varchar to int. This is taking a very long time to update the 95 million rows in the table. Is there another way of doing this, perhaps altering the column definition ?
--
alter table trade add temptflag int

update trade set temptflag = cast(tflag as int)

alter table trade drop column tflag

EXEC sp_rename 'trade.temptflag', 'tflag', 'COLUMN';
--


Sean

Sean_B
Posting Yak Master

111 Posts

Posted - 2009-06-09 : 11:42:15
doing it in batches in a loop seems o be the answer.

Sean
Go to Top of Page

asgast
Posting Yak Master

149 Posts

Posted - 2009-06-09 : 12:05:54
books online say that you can change the type directly, without using buffer column, have you tried it?

http://msdn.microsoft.com/en-us/library/ms190273.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-09 : 12:08:54
quote:
Originally posted by Sean_B

Hi,

I'm running the following code to change a column from varchar to int. This is taking a very long time to update the 95 million rows in the table. Is there another way of doing this, perhaps altering the column definition ?
--
alter table trade add temptflag int

update trade set temptflag = cast(tflag as int)

alter table trade drop column tflag

EXEC sp_rename 'trade.temptflag', 'tflag', 'COLUMN';
--


Sean


is there any existing index on column?
Go to Top of Page
   

- Advertisement -