Friday, March 28, 2014

Difference between CTE and Temp Table and Table Variable

 1)    Temp Tables are physically created in the Tempdb database. These tables act as the normal table and          also can have constraints, index like normal tables.
 2)  CTE is a named temporary result set which is used to manipulate the complex sub-queries data. This              exists for the scope of statement. This is created in memory rather than Tempdb database. You cannot          create any index on CTE.
 3)  Table Variable acts like a variable and exists for a particular batch of query execution. It gets dropped            once it comes out of batch. This is also created in the Tempdb database but not the memory.

No comments:

Post a Comment