sqlsql-serversql-server-profilermultiple-insert

TVP insert shows many SP:Starting and SP:Completed events in SQL Server Profiler


I am profiling an insert query that takes a temporary table as parameter, and seeing that each item being inserted counts towards a SP:Starting and SP:Completed event in SQL Server Profiler.

Here is roughly the query I am doing:

DECLARE @temptable TABLE (id INT)
INSERT INTO @temptable (id) VALUES (0), (1), (2), ..... (500)
INSERT INTO TableOfInts (id)
SELECT id FROM @temptable

When I look at my SQL Profiler, I have a statement for each value I'm inserting in the real table from the temporary table:

EventClass   TextData
SP:Starting  INSERT INTO TableOfInts (id)....
SP:Completed INSERT INTO TableOfInts (id)....
SP:Starting  INSERT INTO TableOfInts (id)....
SP:Completed INSERT INTO TableOfInts (id)....
SP:Starting  INSERT INTO TableOfInts (id)....
SP:Completed INSERT INTO TableOfInts (id)....

500 entries of SP:Starting and SP:Completed

I was wondering if this is normal for this type of query, or if I am doing something wrong somewhere that is causing a bunch of extraneous queries to run.


Solution

  • I figured it out, my table had a default column which called a CLR function to auto-generate it. Each insert would be a call to the scalar function, resulting in a SP:Starting and SP:Completed event showing up for each one.