一个SSMS查询窗口就是一个会话
通过本地临时表验证:
本地临时表仅在当前会话中可见;全局临时表在所有会话中都可见。
本地临时表的名称前面有一个编号符
(#table_name),而全局临时表的名称前面有两个编号符 (##table_name)。
打开一个查询窗口,新建本地临时表,插入数据,并查询
create table #temptable (id int identity(1,1) primary key,
name nvarchar(10) null);
go
insert into #temptable(name) values(‘mark‘),
(‘test‘);
go
select * from #temptable
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
再“新建查询”窗口,
select * from #temptable
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
这是为什么呢?
这两个SSMS查询窗口是两个会话?
sp_who查看下,用事实说话:
52,53那列是SPID,我没有截完整。
SPID即为会话ID,会话ID不同,那即是两个会话了呀!
SQL Server 中本地(局部)临时表,布布扣,bubuko.com
时间: 2024-11-08 19:09:42