Testing SQL Server 2025 Resource Governor tempdb Limits with a Query that Spills a Terabyte
SQL Server 2025 introduces a new Resource Governor capability to manage tempdb usage, along with making Resource Governor available in Standard …
Read MoreEvery now and again, I need use a global temporary table for some testing or demo code.
Each time I do, I stumble a little bit when it comes to checking for the existence of the global temp table, in order to make my code re-runnable.

Here’s the TSQL to check for the object_id of a global temporary table:
SELECT OBJECT_ID('tempdb..##Temp');
GOSo if you’d like to drop the global temp table if it exists, you can do this:
IF OBJECT_ID('tempdb..##Temp') IS NOT NULL
DROP TABLE ##Temp;
GOOr if you’d like to truncate it if it exists, and create it if it doesn’t exist, you can do this:
IF OBJECT_ID('tempdb..##Temp') IS NOT NULL
TRUNCATE TABLE ##Temp;
ELSE
CREATE TABLE ##Temp (
RecordID INT IDENTITY(1,1),
CharColumn CHAR(500) NOT NULL,
CONSTRAINT pk_UserDatabaseTablePK PRIMARY KEY CLUSTERED (RecordID)
)
GOCopyright (c) 2025, Catalyze SQL, LLC; all rights reserved. Opinions expressed on this site are solely those of Kendra Little of Catalyze SQL, LLC. Content policy: Short excerpts of blog posts (3 sentences) may be republished, but longer excerpts and artwork cannot be shared without explicit permission.