Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select a temp table in database when debugging? [duplicate]

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?

like image 756
SleeplessKnight Avatar asked Mar 21 '23 08:03

SleeplessKnight


1 Answers

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.

like image 163
Sajad Karuthedath Avatar answered Apr 27 '23 06:04

Sajad Karuthedath