top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I determine that temporary table exists in SQL Server?

+1 vote
48 views

When writing a T-SQL script that I plan on re-running, often times I use temporary tables to store temporary data. Since the temp table is created on the fly, I'd like to be able to drop that table only if it exists (before I create it).

I'll post the method that I use, but I'd like to see if there is a better way.

posted Apr 30, 2014 by Aastha Joshi

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

CREATE TABLE #Table(id INT)

--Check if it exists
IF OBJECT_ID('tempdb..#Table') IS NOT NULL
BEGIN
PRINT '#Table exists!'
END
ELSE
BEGIN
PRINT '#Table does not exist!'
END

answer Nov 12, 2014 by Manikandan J
Similar Questions
+3 votes

Where does the table variables and temporary tables exist in the memory, in memory or physical drive?

+2 votes

In a stored procedure, for the same table i want to UPDATE if exists else INSERT data.
How ca this be implemented?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...