MargusLehiste
asked on
How can you check if a Global Temporary table exists ?
How can you check if a Global Temporary table exists and if it doesnt - create this table.
You can't have multiple global temporary table with the same name - right?
(although multiple users can create local temporary tables with the same name...)
You can't have multiple global temporary table with the same name - right?
(although multiple users can create local temporary tables with the same name...)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, you cannot have the multiple Global Temporary tables with the same name.
Or a little shorter:
If Object_ID('tempdb..##table _name') Is Null
Create Table ##table_name (col1 int)
If Object_ID('tempdb..##table
Create Table ##table_name (col1 int)
ASKER
kselvia - in 'tempdb..##table_name' what are those 2 dots about?
Or, a little more portable:
If Not Exists(Select * From TempDB.Information_Schema. Tables Where Table_Name = '##Table_Name')
Create Table ##table_name(Col1.Int)
This is guaranteed to work in future versions as well.
If Not Exists(Select * From TempDB.Information_Schema.
Create Table ##table_name(Col1.Int)
This is guaranteed to work in future versions as well.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think Sjoerd was refering to Ram2098's answer rathe than mine. Yes, if you need to reference sysobjects, it is better to reference information_schema tables. Sysobjects may not be supported in the future.