illumi
illumi

Reputation: 458

MS SQL Temporary table

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

SELECT * FROM ##TEMP

and this

SELECT * FROM #TEMP

Upvotes: 4

Views: 6740

Answers (3)

user172839
user172839

Reputation: 1065

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

Upvotes: 1

nimdil
nimdil

Reputation: 1381

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.

Upvotes: 1

roman
roman

Reputation: 117337

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

Upvotes: 10

Related Questions