August 27, 2008 at 7:04 am
Yes thats a good point, temporary tables only exist for the life of the stored procedure (when prefixed with one #), I temporarily forgot about that ;).
August 27, 2008 at 7:36 am
skyline666 (8/27/2008)
Yes thats a good point, temporary tables only exist for the life of the stored procedure (when prefixed with one #), I temporarily forgot about that ;).
That's not exactly true. Temp table exists for the life of the connection. Try to rerun same code in the same query window (same connection id) and you'll get an error saying that table already exists. It's a good practice to always clean up after yourself.
August 27, 2008 at 7:46 am
Aleksandr Furman (8/27/2008)
skyline666 (8/27/2008)
Yes thats a good point, temporary tables only exist for the life of the stored procedure (when prefixed with one #), I temporarily forgot about that ;).That's not exactly true. Temp table exists for the life of the connection. Try to rerun same code in the same query window (same connection id) and you'll get an error saying that table already exists. It's a good practice to always clean up after yourself.
Yes, sorry that is what I meant but didn't say very clearly!
August 28, 2008 at 12:54 am
Aleksandr Furman (8/27/2008)
skyline666 (8/27/2008)
Yes thats a good point, temporary tables only exist for the life of the stored procedure (when prefixed with one #), I temporarily forgot about that ;).That's not exactly true. Temp table exists for the life of the connection. Try to rerun same code in the same query window (same connection id) and you'll get an error saying that table already exists. It's a good practice to always clean up after yourself.
Hi Aleksandr,
Local temporary tables are dropped when the stored procedure completes. The behaviour you describe applies not to stored procedures (unless you use global temp tables instead of local temp tables).
Here is an example that creates a temp table within the stored procedure dbo.Test and tries to select from the table after the procedure completed:
CREATE PROCEDURE dbo.Test
AS
CREATE TABLE #Test (ColA int NOT NULL);
GO
EXEC dbo.Test;
GO
SELECT * FROM #Test;
Best Regards,
Chris Büttner
August 28, 2008 at 1:19 am
It should be 1,5,2,3,3,2
August 28, 2008 at 1:45 am
dgvsbabu (8/28/2008)
It should be 1,5,2,3,3,2
I don't think it should be, can you explain why?
September 15, 2008 at 1:04 am
hi i am not clear this question and answer
pls tell again other solution[/size:discuss:]
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply