MS SQL temp table

I was wondering what is the difference between these two scenarios?

SELECT * FROM ##TEMP 

and this one

 SELECT * FROM #TEMP 
+4
source share
3 answers

##TEMP is a 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 during the first creation or link of tables. Local temporary tables are deleted after a user disconnects from an 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 refer to the table are disconnected from the instance of SQL Server.

see documentation .

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

+10
source

The first (## TEMP) is global - any user can access it, and you can also from different sessions (think of tabs in SQL Server Management Studio). The other is visible only to you.

+1
source

## are global tables that are visible to everyone and are deleted when all connections that reference them are closed.

# are local tables that are visible only to the connection that created it and are deleted after disconnecting the connection.

+1
source

Source: https://habr.com/ru/post/1502963/


All Articles