Possible Duplicate:
Why are temporary tables not removed from tempdb in SQL Server?
We have created Temporary tables in a stored procedure and while running the stored procedure the Temparory table is created in the TempDB.
In my SP I have written code to drop that temporary table after completion of all operations manually.
But it is still there in the TempDB and not dropped. But when I restarted the SQL connection then the table had been dropped. I don’t understand how this type of scenario happen in my DB.
Why are my temporary tables not dropped after completion of their scope?
Can anyone help me out this problem?
I’m not sure why your table is not being dropped, but could you get away with using a table variable (@TableName) instead of a temp table (#TableName)? Then you wouldn’t have to worry about dropping it at all, and it would be removed as soon as it goes out of scope…