Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have stored procedures that need to return a resultset. Because of they they work they need to do several selects to compose those resultsets. So I insert into the table as needed, and at the end I select from it, and then drop it before exiting the procedure.

My question is several parts.

1. If I create a temp table called #Results inside a stored procedure, is the stored procedure it was created in reentrant?

2. If I create a temp table called #Results inside a stored procedure, and that procedure gets called concurrently by two different queries, how many temp tables were created to fulfill those queries - in total - one or two?

3. If I create a temp table called #Results inside a stored procedure, can stored procedures it calls gain access to that temporary table or do I need to create ##Results temp table to do that?

What I have tried:

Currently I am simply creating and dropping #Results within the scope of one routine, but I have concerns about reentrancy and otherwise concurrency .
Posted
Updated 9-Nov-21 16:33pm

1 solution

Regarding each question you had

1. From the point of view of the table, the procedure should be re-entrant. The local temporary table is automatically dropped when it goes out of scope, when the procedure is finished in this case. Of course if you drop the the table yourself it's completely fine

2. If the tables are local temporary tables like in your example then two separate tables will be created. Local temporary tables are session specific so DBMS adds an unique identifier to the end of the actual table name to distinguish the session specific tables. This is done automatically under the hood and does not effect your naming. However, because of this the maximum length of a temporary table name is 116 characters

3. Nested procedures can access the temporary table as long as they are run inside the same session and same account
 
Share this answer
 
Comments
honey the codewitch 9-Nov-21 22:35pm    
Thank you! That clears it up for me perfectly.
Wendelius 9-Nov-21 22:52pm    
Glad to be of service :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900