In situations where a .Net Aspx Page or Web Service requires to do approximately 20-200 row inserts into a table, which of the following approaches would you recommend and why? Small performance gains will likely mean I’ll still use the method that I am most familiar with, so please tell if its not going to make much of a difference. Any general guidance as to when it really makes sense to use one over the other would be appreciated.
- Table Valued Parameters
- SqlBulkCopy Class
- XML Parameter in a Stored Procedure and Using XQuery
- Twenty to Two Hundred Individual Insert Stored Proc Calls
Other Notes: The amount of logic processing required for each Insert varies, but it can be assumed that little will be required. I’m mostly interested if there could be a significant amount of performance / ease of use / other benefit to one of the four choices for these tiny batch inserts that will be iterated dozens to hundreds of times per day.
For such a small amount of rows I would personally go with Table Valued Parameters – that’s one of the best uses for them.
I
SqlBulkCopyas more of a workhorse for much larger amounts of data and for multiple tables.XML parameters would be very processors intensive and XML is still not as native to SQL Server as TVPs are.
Multiple inserts is the worst option by far – 200 connections, 200 transactions etc…
The real answer regarding which option performs best depends on your particular situation. You need to test all of the approaches and go with the best one for you.