Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS SQL Temporary table

I was wondering, what is the difference between these two scripts?

SELECT * FROM ##TEMP

and this

SELECT * FROM #TEMP
like image 683
illumi Avatar asked Dec 15 '22 06:12

illumi


1 Answers

##TEMP is global temporary table, #TEMP is local.

Local temporary tables are visible only to their creators during the same connection to an instance of SQL Server as when the tables were first created or referenced. Local temporary tables are deleted after the user disconnects from the instance of SQL Server.

Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.

see documentation.

Actually here is almost the same question with answer - Local and global temporary tables in SQL Server.

like image 120
Roman Pekar Avatar answered Jan 13 '23 20:01

Roman Pekar