Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for Existance of #Temp tables

Status
Not open for further replies.

skuhlman

Programmer
Jun 10, 2002
260
US
Is there a way to check for the existance of a #Temp table?

Within a nested trigger I am running into problems creating a #Temp table because it sometimes already exists. I'd like to avoid trying to re-create the table if it is there, otherwise I need to create it so that it can be used.
 
2 ways

create table #temp(id int)


if object_id('tempdb..#temp') is not null
begin
print '#temp exists!'
end
else
begin
print '#temp does not exists!'
end



if object_id('tempdb..#temp','u') is not null
begin
print '#temp exists!'
end
else
begin
print '##temp does not exists!'
end

Denis The SQL Menace
SQL blog:
Personal Blog:
 
I suggest you change the table name to something else. For example, if your trigger is on a table named BLAH, and it's an update trigger, then...

#TempUpdateBlah



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top