Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Temporary Table

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-11-25 : 02:53:12
how can i check if the temporary table exists tnas delete it
i write this ,but it is not found my table even that table is exist

If Exists
(Select * From Sysobjects Where Name Like N'#Table')
Drop Table dbo.#Table

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 02:55:30


If Exists
(Select * From tempdb..Sysobjects Where Name =N'#Table')
Drop Table dbo.#Table

or

If object_id('tempdb..#Table') is not null
Drop table #table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-11-25 : 02:55:42
Hi

Temp tables are exists only in Tempdb...why need to check the temp table are exists or not

Temp table is live only the current session .



-------------------------
R...
Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-11-25 : 04:18:28
i found if i crreate a temporary table like #T so , in the sysobjects table is save as
'#T__________________________________________________________________________________________________________________000000000464'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 04:24:26
quote:
Originally posted by inbs

i found if i crreate a temporary table like #T so , in the sysobjects table is save as
'#T__________________________________________________________________________________________________________________000000000464'


Yes. But have you tried what I replied?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-11-25 : 04:29:41
Use


If object_id('tempdb..#Table') is not null
Drop table #table

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 04:31:49
quote:
Originally posted by senthil_nagore

Use


If object_id('tempdb..#Table') is not null
Drop table #table

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/



Have you seen my first reply?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -