0

How do I lock a global temporary table in a stored procedure that's getting created and populated by a SELECT INTO statement? For example:

SELECT * 
INTO ##TempEmployee   
FROM Employee   

This stored procedure is executed for generating reports and it's there in every client database (multi-tenant architecture using different DB per client). I do not want data in this global temporary table to be shared between clients when the report is generated concurrently. I don't have a choice but to use global temp table because I use it for generating columns on the fly using PIVOT.

Dave.Gugg
  • 6,561
  • 3
  • 24
  • 43

2 Answers2

1

Why not include it inside a transaction block like

begin transaction
SELECT * 
INTO ##TempEmployee   
FROM Employee 
Rahul
  • 76,197
  • 13
  • 71
  • 125
0

Try this,

WorkDummySQL

  create table rr(id integer,name varchar(20))
    insert into rr values(1,'aa')
    select * from rr

Tempdb

select * into ##ta from WorkDummySQL.dbo.rr

Vinoth_S
  • 1,380
  • 1
  • 12
  • 15