We know that in SQL Server, creating a table with # means "local temp table" and ## means "global temp table".
But when I create a table like below:
create table ###MyTable(IntColumn int, ValueColumn varchar(100))
Is this table a local or global temp table? How can I test it? When I tried to select it via:
Select * from #MyTable -- SQL said it doesn't exists
Select * from ##MyTable -- SQL said it doesn't exists
Select * from ###MyTable -- I get the output
If third case is true, doesn't it mean that this is general table with the name ###MyTable? And wouldn't I see this table in my SSMS table explorer like every other physical table?
What will happen if I start adding multiple # (hashes) before my table name?
It is a
global temp table.It is considering the third#as part of the tablename. If you check thetemdb databaseyou can see the table without the session ID. If the temp table is created as local temp table then you can see the particularsessionIDwill be appended with the temptable name, Since there is nosession IDappended with the temp tablename it is aglobal temp table.After running the above query
GOTO Server -> Databases -> System Database -> Tempdb -> Temporary Tables
you can find the created
Global temptablejust like the below image.