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