Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

Local temp table created inside stored procedure does not drop automatically at the end of current session

$
0
0

Here I just want to play with local temp table behavior inside a stored procedure. I still create and drop temp table inside the same proc.

Below is the sample proc:

/*********************************************/

CREATE PROCEDURE dbo.test2

AS
/*
exec dbo.test2
*/
begin
begin try
    CREATE TABLE #test2(test2 int)

return
end try
begin catch
    select 'This is inside CATCH statement of proc test2!'
return
end catch
end
GO

/*********************************************/

After I close the query window that runs "exec dbo.test2" and the conn session is supposed to be closed(?). When I open another query window and run the query below:

select * from tempdb.sys.columns 
where name in ('test2')

I still see this record there, which means the temp table still exists after the session is closed(?). This column is unique for sure.

Any explanation here?

Thanks.

Shigui,



Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>