Search code examples
sqlsql-serversql-server-2005copying

How to copy a huge table data into another table in SQL Server


I have a table with 3.4 million rows. I want to copy this whole data into another table.

I am performing this task using the below query:

select * 
into new_items 
from productDB.dbo.items

I need to know the best possible way to do this task.


Solution

  • If you are copying into a new table, the quickest way is probably what you have in your question, unless your rows are very large.

    If your rows are very large, you may want to use the bulk insert functions in SQL Server. I think you can call them from C#.

    Or you can first download that data into a text file, then bulk-copy (bcp) it. This has the additional benefit of allowing you to ignore keys, indexes etc.

    Also try the Import/Export utility that comes with the SQL Management Studio; not sure whether it will be as fast as a straight bulk-copy, but it should allow you to skip the intermediate step of writing out as a flat file, and just copy directly table-to-table, which might be a bit faster than your SELECT INTO statement.