|
I have a stored procedure sp1. Inside this sp I used a temp table t1. I have another stored procedure sp2. Can I call sp1 from sp2? What is the scope of t1 in this case. I faced this question in an interview. Thanks in advance.
(comments are locked)
|
|
From MSDN BOL
(comments are locked)
|
|
The scope of the temp table depends on whether it was created as local (name begins with #) or as global (name begins with ##). Local temp table is visible to the connection created it, while the global one is visible to all connections buu the moment the last connection using the global temp table is closed the table goes out of scope (gets dropped). In your case, yes you can have sp2 calling sp1 which creates temp table and after the sp1 bails out your sp2 can still continue talking to temp table if it is global, for example:
The above allows exec dbo.sp2; returning 2 sets, but if you replace the ## with # then exec dbo.sp2 will bark as #t will not be available for it was local and its scope was limited to sp1 proc. Oleg
(comments are locked)
|

