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 Hugo Kornelis on 09/21/05 00:03

On Tue, 20 Sep 2005 05:46:33 GMT, rdraider wrote:

>Hi all,
>I'm looking for a way to re-number inventory items. The items exist in 50+
>tables, hundreds of fields and there are several thousand items. Maybe one
>table could hold the list of old & new items, another table holds the list
>of tables/fields to update? How can this be done without needing a million
>individual update statements?
>
>A brute force method may look like:
>update table1 set field1 = newitem where field1 = olditem
>
>update table1 set field2 = newitem where field2 = olditem
>
>update table2 set field1 = newitem where field1 = olditem
>
>Thanks for any input.
>
>

Hi rdraider,

If you have all the foreign key constraints in place, and you have
created them with the cascading updates option, it's actually as simple
as

UPDATE MainTable
SET Column = New value
WHERE Column = Old value

The cascading updates will make sure that the change is rolled out to
all other tables.

Since you have many tables, this might take some time. During that time,
all locks takes will make concurrent use of the database nigh on
impossible, so plan to do this during down time.

Also, make sure that your transacion log is big enough to hold all
changes. Grow it manually before starting if needed. Autogrow is quite
slow, since it allocates only a bit of extra disk space at a time.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

 

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

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