简体   繁体   中英

SSIS Data flow vs Custom transfer scripts vs Bulk Insert

When copying the results of a view from a database on one server, to a another database on a new server (both running SQL Server 2008), which of the following methods is the likely to be the most efficient?

1. SSIS Dataflow task with OLE DB Source/Destination

忽略错误,只是为了演示目的而设置

2. Custom scripts

eg

using (SqlConnection connection = new SqlConnection(sourceConnectionString))
using (SqlCommand command = new SqlCommand(sourceQuery, connection))
{
    connection.Open();
    using (SqlDataReader reader = command.ExecuteReader())
    {
        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnectionString))
        {
            bulkCopy.DestinationTableName = destinationTable;
            //Any Column mapping required
            bulkCopy.WriteToServer(reader);
        }
    }
}

3. SSIS Bulk Insert

I don't see how this would be any different to using custom scripts, but without the added inflexibility that it only works with tables/views and not stored procedures.


I realise this is not quite like for like comparison because there are additional levels of logging and error handling etc available with the various options, but lets assume I require no logging at all to try and make the playing field as even as possible.

According to this SO Post , BULK INSERT performs better than SqlBulkCopy. However, according to this post, the DataFlow task is preferred over the Bulk Insert SSIS task

This isn't really answering your question directly, but...

The short answer to your question is probably to try different approaches using a representative data set and see for yourself. That will give you an answer that is more meaningful for your environment than anyone on SO can provide, as well as being a good way to understand the effort and issues involved in each option.

The longer answer is that the SSIS Bulk Insert task is most likely the slowest, since it can only load flat file data . In order to use it, you would have to export the data to a file on the source server before reloading it on the target server. That could be useful if you have a very slow WAN connection between the servers, because you can compress the file before copying it across to minimize the data volume, otherwise it just adds more work to do.

As for the difference between SSIS and SqlBulkCopy I have no personal experience with SqlBulkCopy so I can only suggest that if there is no clear 'winner' you go with the simplest, easiest to maintain implementation first and don't worry about finding the fastest possible solution until you actually need to. Code only needs to run fast enough, not as fast as possible, and it isn't clear from your question that you actually have a performance problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM