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; 
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts