Temporary tables are created using
“create table #table” (local)
“create table ##table” (global)
Temporary tables are created in tempdb. They are categorized into local , global temporary tables.
Local tables can be accessed by the process (SPID), by which they had been created and once the process is closed, they are destroyed automatically.
Global tables can be accessed by all the processes after it has been created. Once created, they are still accessible till last reference is closed or the process, which is created is closed, whichever is earlier.
Unlike Temporary tables, table variables reside in memory. This is the major advantage over temporary tables.
P.S: SQL Server converts table variable into temporary table automatically, if the resultset holded by table variable is too big. Hence, While working on large data to hold temporarily, it is recommended to opt for temp tables.
No comments:
Post a Comment