SQL Server 2008 bulk update using stored procedure -
i have 2 tables in db. each "name" column , "count" column each.
i update count column in second table count in first table "name" columns equal.
example:
first table:
name count
jack 25
mike 44
name count
jack 23
mike 9
david 88
result (the second table that...)
name count
jack 25
mike 44
david 88
notes:
1. both tables huge. (although second table bigger...)
2. update must fast possible...
(if there more options other stored procedures, love hear.)
3. "count" defined bigint while "name" nvarchar(100)
4. "count" field in first table bigger equivalent in the
second table.
i think there more options (other stored procedure) maybe merge or transaction long fastest way...
thanks!
the best way keep simple
update table2 set count = t1.count table1 table2.name = table1.name , table2.count <> table1.count
if performance of query not satisfactory due size of tables best solution partition tables based on name field. query can run different threads @ same time , filter based on name satisfy partition function.
for example: (assuming name varchar(20) column)
update table2 set count = t1.count table1 table2.name = table1.name , table2.count <> table1.count , table2.name between cast('jack' varchar(20)) , cast('mike' varchar(20))
(the cast on strings big sql server partition elimination.)
Comments
Post a Comment