Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does BULK INSERT work internally?

Could someone please explain how does BULK INSERT internally work and why is it much faster than the normal INSERT operations ?

Regards, Shishir.

like image 393
invinc4u Avatar asked Nov 09 '09 16:11

invinc4u


1 Answers

BULK INSERT runs in-process with the database engine of SQL Server and thus avoids passing data through the network layer of the Client API - this makes it faster than BCP and DTS / SSIS.

Also, with BULK INSERT, you can specify the ORDER BY of the data, and if this is the same as the PK of the table, then the locking occurs at a PAGE level. Writes to the transaction logs happen at a page level rather than a row level as well.

In the case of regular INSERT, the locking and the Transaction log writes are at a row level. That makes BULK INSERT faster than an INSERT statement.

like image 69
Raj More Avatar answered Sep 19 '22 23:09

Raj More