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
 The quickest way to run this query

Author  Topic 

help_needed
Starting Member

12 Posts

Posted - 2009-02-08 : 12:59:37
Hi

I need to update a table with data from another table and am trying to find out the best way to write it so it doesn't take days to complete due to the amount of records. The 1st table (vroll_2006) has approx 40,000,000 records and the 2nd (ctbands) has 26,000,000. I The table is linked by a column called addressurn and the one I want to update in the 1st table is called ctb. I have come up with the one below but not sure if this is the right way to go or not??

update vroll_2006
set ctb = ctbands.ctb
from
ctbands
inner join
vroll_2006
on vroll_2006.addressurn = ctbands.addressurn

Any thoughts or help will be very appreciated

Thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-08 : 13:07:50
Shouldn't it be like this? Also update in batches so you don't blow off the log file.

Update T
set T.ctb = C.ctb
from vroll_2006 T
inner join ctbands C
On T.addressurn = C.addressurn
Go to Top of Page

help_needed
Starting Member

12 Posts

Posted - 2009-02-08 : 14:31:25
Thanks for your help. How would you make it update in batches then?

Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-08 : 16:25:04
Did you search for it? Do you have Datetime column?
Go to Top of Page

help_needed
Starting Member

12 Posts

Posted - 2009-02-08 : 16:47:29
quote:
Originally posted by sodeep

Did you search for it? Do you have Datetime column?


No the only columns in vroll_2006 are

title, forename, surname, address1, address2, town, county, postcode, addressurn, ctb

and in ctbands only 2 columns which are

addressurn, ctb
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-08 : 21:41:26
whats the primary key of table? is there not an id column?
Go to Top of Page

help_needed
Starting Member

12 Posts

Posted - 2009-02-09 : 03:22:06
The addressurn is a unique number for each address which is in both tables
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-09 : 03:28:55
then split as batched based on addressurn values
Go to Top of Page
   

- Advertisement -