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)
 how to drop Temp table?

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-10-22 : 06:06:12
I have a question regarding Temporary Tables.

When I Create a Temporary table from a SP , Where it is created??
Whether it is created with in my own Database or it is created in any other database.

and If I want to drop any Temporary table , How can I check it's existence


thanks in advance

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-22 : 06:14:06
Temp tables are created in tempdb

you can check whether it exists and drop it if it does with this.

IF OBJECT_ID('tempdb..<name of temp table>') IS NOT NULL DROP TABLE <name of temp table>

Temp tables (1 #) are local to your scope. That means that if they are created inside a sp they are only available to that stored proc (and any objects it calls)

Hope this helps.

-------------
Charlie
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-22 : 08:01:31
Note that the temp table created inside a procedures is automatically dropped after the execution of the procedure

Madhivanan

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

- Advertisement -