In a C# app, what is the most optimal way to insert many records into sql server?

Posted by Otter on Stack Overflow See other posts from Stack Overflow or by Otter
Published on 2010-04-07T19:20:53Z Indexed on 2010/04/07 19:23 UTC
Read the original article Hit count: 140

Filed under:

I need to perform a very large sql server insert from a c# application. Somewhere in the range of 20,000 through 50,000 records.

What is the fastest way through SQL server to perform the insert?

There are several options I know of, but I don't know which is the fastest.

   insert into MyTable(column1, column2, ..., column*)
   select 'value','value',...,'value'
   union
   select 'value','value',...,'value'

VS

   insert into MyTable(column1, column2, ..., column*)
   exec('select ''value'',''value'',...,''value'''
        'select ''value'',''value'',...,''value''')

VS

   bulk insert from a data file

VS

   Any better way that you know of :)

© Stack Overflow or respective owner

Related posts about sql