Insert One Million Rows into SQL Server - How to Use SqlBulkCopy

preview_player
Показать описание
This week’s video in our Data Engineering playlist is for those who are learning to code ETL and data pipelines in Microsoft’s .Net languages. Knowing how to perform massive inserts into database tables is a very important skill! If you’re getting stuck and are either doing one insert per row, or trying to write consecutive large multiple insert statements (SQL Server 2008+), then SqlBulkCopy is for you! It handles the task of inserting large amounts of data in an efficient way. SqlBulkCopy is part of SqlClient, and mastering it will give you many advantages, particularly in Microsoft environments. Though this example is written in VB.Net, the concepts can be used for other .Net flavors, including C#. Let’s insert one million rows!

Follow us on social media:

Get Microsoft Office including Access:

Got a YouTube Channel? I use TubeBuddy, it is awesome. Give it a try:

sqlclient sqlbulkcopy
sqlclient sqlbulkcopy sql server
how sqlbulkcopy works
sql bulk copy
sqlbulkcopy without column mapping
sqlbulkcopy without identity column
sqlbulkcopy with identity column
sqlbulkcopy vs bulk insert
sqlbulkcopy example
sqlbulkcopy timeout
sqlbulkcopy performance
sqlbulkcopy column mapping
sqlbulkcopy writetoserver
Рекомендации по теме
Комментарии
Автор

Very helpful article Sean.

Is there a way to ensure all the rows were inserted successfully, other than counting after insertion?

mittalpa
Автор

Thanx. I will compare one table with 5 tables and copy data in Destination Table if Not Existe Id. How Can I do that?

mehdisoleimanian
Автор

If we do have any checking for duplication does the performance will be the same?

paang
Автор

Can we use use this to update a column in a table? If yes, will it work with the same efficiency ?

parasvillis
Автор

Need to insert list of dto objects in database using sqlbulkcopy....can u suggest how to do it

sharayuwagh
Автор

please what if i have tables and the tables it relation and it take forgain key of another table how i can deal with this and thanks for you sir

behappey
Автор

I've a question for you?
Why sql server memory still growth up,
When we use sqlbulkcopy
Is there any solution to handle it?

manadochannel
Автор

I am already using bulkcopy for doing the insertion. But let's say there are 100M rows in a table and you want to delete 1M row from there. How you do it in a faster and optimal way? (we have the row ids) but deleting using the id one by one still needs a significant amount of time. Is there anything that does the delete operation like bulkcopy/bulkDelete?

dfytq
Автор

Thanks for the video Sean. Couple of quick questions. My end goal is to copy a table from one database to another database. These tables are located in the same server

1) How do I differentiate between source and destination tables
2) Could you explain how for loop works when I want to copy the same contents?

Ananth