C# 在SQL Server中有没有一种方法可以插入到Destitable parallely中?

C# 在SQL Server中有没有一种方法可以插入到Destitable parallely中?,c#,sql,C#,Sql,我有一个动态SQl查询,如下所示 Create #TempTable(ColumnA int, ColumnB int, ColumnC Int) Insert into #TempTable(select A,B,C from Table1 where some condition formed dynamically) Insert into #TempTable(select A,B,C from Table1 where some condition formed dynamica

我有一个动态SQl查询,如下所示

Create #TempTable(ColumnA int, ColumnB int, ColumnC Int)

Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)

select * from #TempTable
drop table #TempTable
注意:插入到TESTERABLE中的insert语句的数量可能从10到100不等,因此需要花费大量时间来执行


我想知道的是,SQL server 2008 R2中是否有一种方法可以并行执行Insert语句并缩短执行时间???

创建一个varchar变量来保存Insert语句。添加While循环并将insert语句附加到varchar变量。然后可以这样执行sql:sp_executesql@sql

临时表的替代变量是表变量,它可以执行我们可以在临时表中执行的各种操作。下面是使用表变量的语法

Declare @TempTable TABLE(
ColumnA int, ColumnB int, ColumnC Int)

Insert into @TempTable
select 1 as ColumnA,2 as ColumnB,3  as ColumnC

Tablevariable对于较少的数据总是有用的

你的执行时间花在哪里?CPU计算或IO?谁在创建动态形成的每个条件?您的SQL代码或外部程序?与其选择,还不如只从中选择并删除它,然后尝试将查询合并在一起。这样做似乎有很多多余的工作。另外,根据您实际的动态逻辑,可能有更好的方法完全解决这个问题。