[dba-SQLServer]something about temp tables...

Francisco H Tapia my.lists at verizon.net
Fri Aug 29 14:44:25 CDT 2003


I have the following similar statement in a tsql procedure that errors 
out telling me that there already is a #tmp object in the database... if 
I read the TSQL correctly, the #TMP does not acctually get created on 
the ELSE statement if the 1=1 statement is true.  So why the error? 
Thanks in advance....

IF 1= 1 BEGIN
      IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE ID = 
OBJECT_ID(N'tempdb..#tmp')) BEGIN
	DROP TABLE #tmp
END

	CREATE TABLE #tmp(tID INT IDENTITY (1,1) NOT NULL,Hcode VARCHAR(50))
      END
ELSE BEGIN
      IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE ID = 
OBJECT_ID(N'tempdb..#tmp')) BEGIN
	DROP TABLE #tmp
       END
	CREATE TABLE #tmp(tID INT IDENTITY (1,1) NOT NULL,Hcode VARCHAR(50))
END



-- 
-Francisco



More information about the dba-SQLServer mailing list