You are here: Re: How to update 1000s of items in 50 tables « MsSQL Server « IT news, forums, messages
Re: How to update 1000s of items in 50 tables

Posted by Erland Sommarskog on 09/21/05 10:43

Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
> In that case, you'll have to bite the bullet and use a list of update
> statements. One for each table. Do enclose all update statements in a
> transaction and include error handling, so that you don't end up with
> the new value in half of your tables changed and the old value in the
> other half. (Instead of enclosing all in a transaction, you could take a
> backup before the conversion starts and restore if something goes
> wrong).


Also, one more important thing here. Don't do:

BEGIN TRANSACTION
go
UPDATE tbl
SET ...

IF @@error <> 0
go
UPDATE nexttbl

That is, don't split up the job in several batches, because some errors
causes SQL Server to abort the batch and rollback the transaction. If you
have multiple batches, you could end up having run the latter half, while
the first was rolled back.

I would recommend that you put all this stuff in a stored procedure, rather
than just a script.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация