문제

My background process is bulk updating/inserting data. I need to store some data in temp table for later use. I have 5 temp tables. If I use temporary table(CREATE TABLE #T) then it will take 2-3 seconds but if I use table variable(DECLARE @T TABLE) then it takes more than 90 seconds. Here is a sample temp table,

CREATE TABLE #TempAttributes
(
    AID int
    ,PID int
    ,ATypeValue nvarchar(MAX)
    ,ATypeKey nvarchar(MAX)
    ,PLanguageID int
);

Why table variable is very slow?

도움이 되었습니까?

해결책

I guess it is because the Table Variable insertion does not support the parallel plan.

Parallel Query Processing is a proccess of optimization in parallel queries that is implemented in MsSql and the temporary table benefits from it whereas the Table Variable does not.

This is one of the main reasons why we do not use a table variable for large set of data (when the scope is of no concern).

Look here for more information.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top