MS SQL Tips & Tricks

How to check if temporary table exists

To test existence of temporary table we have to use OBJCECT_ID function that gives us ID of the object or NULL if object does not exist. We have to remeber that temporary table are always placed on tempdb database.

IF OBJECT_ID('tempdb..#temp') IS NOT NULL
  drop table #temp

Learn more tricks

Add Comment