I have some C# code that is populating a TVP and then calling a stored procedure in SQL Server where it passes in that TVP. It utilizes the standard ADO.NET DataTable and the Rows.Add
to populate the rows.
When the sqlCommand.ExecuteNonQuery()
runs, if you capture a SQL trace in SQL Profiler, you will see it something like this, where it populates each row of the TVP in separate insert statements.
declare @p1 dbo.BigIntTable -- This is a table type
insert into @p1 values(1)
insert into @p1 values(2)
insert into @p1 values(3)
insert into @p1 values(4)
insert into @p1 values(5)
exec dbo.MyProc @InputTVP=@p1
go
I want it to insert all the values in one statement, as seen below. The example below is valid SQL and performs much better than the above generated by ADO.NET. Any ideas?
declare @p1 dbo.BigIntTable -- This is a table type
insert into @p1
values
(1)
,(2)
,(3)
,(4)
,(5)
exec dbo.MyProc @InputTVP=@p1
go