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
 begin
  drop table #temp
 end

Learn more tricks

Add Comment

Comments