Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

reliability of using global temp table in shared stored procedures

$
0
0

Hello - In our reporting environment we have some reports that require the same basic information as a starting point so we have shared stored procedures that fulfill this need.  For the case in question, the shared sproc creates a global temp table and populates it with data.  Each report has it's own stored procedure which calls the shared sproc - these reports use the global temp table (generated by the shared sproc) in their initial SELECT statements to get the needed detail data.  The report specific sprocs usually perform additional logic (ie. aggregation) to tailor the final output data to the report's requirements.

Suppose we have report A and report B which source their data from sproc A and sproc B, respectively.  Here is a diagram of the shared sproc technique:

In the shared sproc here is what happens:

  1. if the global temp table exists, drop it
  2. explicitly create the global temp table
  3. populate the global temp table with data

The concern with this technique is the potential for failure or unexpected results if reports A and B call the shared sproc within milliseconds of one another.  Does anyone know if SQL Server "locks" the shared sproc for report A/sproc A and allows that to complete before allowing report B/sproc B to call the same shared sproc?



Viewing all articles
Browse latest Browse all 23857

Trending Articles



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