2014-06-12 3 views
1

나는SQL Server에서 TempTable에 병렬로 삽입하는 방법이 있습니까?

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 

참고 아래와 같이 동적 SQL 쿼리를 다음 #TempTablecan에 삽입 문장의 수는 10 ~ 100 다를 따라서는 내가 싶었던

을 실행하는 시간이 많이 걸립니다 알다시피 SQL Server 2008 R2에서 Insert 문을 병렬로 실행하고 실행 시간을 줄일 수있는 방법이 있습니까?

+1

실행 시간은 어디에 사용됩니까? CPU 계산 또는 IO? – qxg

+0

"동적으로 형성된 조건"을 누가 작성합니까? SQL 코드 또는 외부 프로그램? –

+0

외부 프로그램 – David

답변

0

삽입 문을 보유 할 varchar 변수를 만듭니다. While 루프를 추가하고 insert 문을 varchar 변수에 추가합니다. 그런 다음 sql을 다음과 같이 실행할 수 있습니다. sp_executesql @sql

0

임시 테이블의 대안은 Temp 테이블에서 수행 할 수있는 모든 종류의 작업을 수행 할 수있는 테이블 변수입니다. 다음은 테이블 변수를 사용하는 구문입니다.

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

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

테이블 변수는 항상 적은 데이터에 유용합니다.

관련 문제