Check if a Temporary Table Exists

Check if a Temporary Table Exists

When working with dynamic SQL queries, you will encounter situations in which you will work with temporary tables. Knowing whether a temporary table exists or not is vital and can save a lot of time whilst testing a query.

In the following example, I check if a temporary table named #T exists. If it does, I drop it:

IF OBJECT_ID('tempdb.dbo.#T', 'U') IS NOT NULL  DROP TABLE #T; 

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist