Is it possible for SqlBulkCopy to construct a table from a SQL selection?



Can SqlBulkCopy create a table, kind of like a SELECT INTO?

10/20/2010 5:35:01 AM

Accepted Answer

It seems that SqlBulkCopy can not create tables by itself. The destination table has to be predefined. In the case where the destination has got an auto incremental identity (int), just use a 1 in the select statement i.e.


SQL Server will handle the auto increment by itself.

5/20/2013 2:42:14 AM

Popular Answer

I think answer above wasn't quite clear.

You must create table with SQL. There is no other way. And if you need just to create column structure, then it is quite simple if your source is in the same server, it is enough to do this:

Select * from source_table into destination_table where 1=2

If your source is not in same server (e.g. it is excel or dbf file or whatever), the easiest thing to do is to connect to it with ODBC (or SQL if possible), and send him:

    Select * from source_table where 1=2

and then collect result into DataTable. Then in second step you should create stored procedure on your destination server that will take that table as argument and then insert it into new table.

A bit more precisely, try this for SQL procedure:,339028455,339282577,00.htm

And create SqlCommnand object in c# and add to its Parameters collection SqlParameter that is SqlDbType.Structured

I didn't go into every single detail, but hope that it can help.

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