Domanda

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

SELECT * FROM ##TEMP

and this

SELECT * FROM #TEMP
È stato utile?

Soluzione

##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.

Altri suggerimenti

The first one (##TEMP) is global - anyone can access it's content and also you can from different sessions (think of tabs in SQL Server Management Studio). The other is only visible by you.

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

# are local tables that is visible to only the connection that has created it and are deleted once that connection has been disconnected.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top