Is there a BulkUpdate command in SQL Server 2008 that is equivalent to BulkCopy?

c# sqlbulkcopy sql-server sql-update

Question

I've employedBulkCopy command to bulk transfer between 3 and 5 million rows of data from one table to another. These rows need to be updated.

Exists anyBulkUpdate comparable to the commandBulkCopy command? I'm using C# and ASP.NET.

2
2
7/18/2015 4:01:33 PM

Expert Answer

Here, a typical strategy is:

  • Using SQL BulkCopy, bulk-load data into a staging table that is empty and has the same fields and data types as the production system's production tables.
  • To change the values in the actual data, perform an update by linking the real data to the staging data.
2
1/14/2012 8:49:29 AM

Expert Answer

I am the project's owner, which is Disclaimer.

The Bulk Operations Library makes it possible to quickly insert, delete, update, and merge millions of records.

If you are already familiar with the SqlBulkCopy class, it's quite simple to understand and utilize.

var bulk = new BulkOperation(connection);
// ... Mappings ....

bulk.BulkUpdate(dt);
-1
3/11/2016 6:15:55 PM

Popular Answer

Not at all, no.

What exactly is a lac?

This aid is zzz-13 zzz

http://itknowledgeexchange.techtarget.com/itanswers/bulk-update-in-sql-server-2005/

Assuming that you have a column with distict values to show you which rows are which between the two tables this can be done with a simple update statement.

UPDATE TableA
SET TableA.A1 = TableB.B1,
    TableA.A2 = TableB.B2  
FROM TableB  
WHERE TableA.A3 = TableB.B3

If you are worried about creating one massive transaction you can batch the operation into smaller chunks. This is done via the TOP keyword.

UPDATE TOP (1000) TableA
SET TableA.A1 = TableB.B1,
    TableA.A2 = TableB.B2  
FROM TableB  
WHERE TableA.A3 = TableB.B3
      AND TableA.A1 <> TableB.B1
      AND TableA.A2 <> TableB.B2

You can put that into a loop...

Another link (with essentially the same answer) is provided here:

http://www.sqlusa.com/bestpractices2005/hugeupdate/



Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow