I create a temp table #temp1 in code, then insert the table in code. I want to select the table in sqlserver when debugging the code. but It can’t . sql server Prompt no talbe called the name . even in database tempdb. how to select a temp table in database when debugging?
Asked
Active
Viewed 6.8k times
4
-
4try double ##temp1 when creating and accessing. It makes it global – Valamas Dec 12 '13 at 09:26
1 Answers
9
insert into ##temp1 select * from TableName
select * from ##temp1
Explanation:
We need to put "##" with the name of Global temporary tables. Below is the syntax for creating a Global Temporary Table:
CREATE TABLE ##NewGlobalTempTable(
UserID int,
UserName varchar(50),
UserAddress varchar(150))
The above script will create a temporary table in tempdb database. We can insert or delete records in the temporary table similar to a general table like:
insert into ##NewGlobalTempTable values ( 1, 'Abhijit','India');
Now select records from that table:
select * from ##NewGlobalTempTable
Global temporary tables are visible to all SQL Server connections. When you create one of these, all the users can see it.

Sajad Karuthedath
- 14,987
- 4
- 32
- 49