2 ms·
It's interesting to see how the code pulls it off. If you run Profiler while this runs, you'll see a table variable being created, and then an insert statement
by pikewood 14y ago
It's interesting to see how the code pulls it off. If you run Profiler while this runs, you'll see a table variable being created, and then an insert statement for each row into that temp table. My guess is that the main performance gain comes from inserting into a table that doesn't require checks against constraints, etc., but eventually the overhead for all those individual inserts means that SqlBulkCopy wins out.
And, the need to define your UDTs is a bit of a pain. But to prevent a glut of UDTs in the db, I've tried to make common UDTs that would commonly be used, such as
CREATE TYPE [dbo].[udt_IntTable] AS TABLE(
[Item_Key] [int] NULL
)
One more point: it's probably best practice to use the TypeName property when using these, as it's required when using a UDT against a parameterized statement that's not a sproc.
param.TypeName = "item_drop_bulk_table_rev4";
- gnaritas 14y ago> My guess is that the main performance gain comes from inserting into a table that doesn't require checks against constraints My guess would it's because inserting into table variables isn't logged; doubt it has anything to do with constraints. This turns all those individual statements into a single bulk insert, a single larger log operation instead of many small ones.