SQL Server:在新查询窗口中查询临时表
我使用以下脚本创建临时表
SELECT *
INTO #TEMP
FROM [mySchema].[Mytable]
临时表位置位于系统数据库>Tempdp>临时表>dbo.#Temp
如何从 SQL Server Management Studio (SSMS) (V18) 查询 SQL Server 新查询窗口中的临时表.9.2)
基于 Zaynul Abadin Tuhin 答案:我们可以通过创建 ##Temp
SELECT *
INTO ##TEMP
FROM [mySchema].[Mytable]来查询全局临时表
I create a temp table with the following scripts
SELECT *
INTO #TEMP
FROM [mySchema].[Mytable]
The temp table location is at System Databases>Tempdp>temporary table>dbo.#Temp
How can I query the temp table in SQL Server New Query Windows from SQL Server Management Studio (SSMS) (V18.9.2)
Based on Zaynul Abadin Tuhin Answer: We can query the global temp table by creating ##Temp
SELECT *
INTO ##TEMP
FROM [mySchema].[Mytable]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如前所述,使用单个哈希/磅
#
前缀创建的临时表仅对创建它的连接可见。但是,没有什么可以阻止您在 tempDB 中创建普通用户表并从 TempDB 现有的各种优化中受益。
当然,您创建的任何表都需要自己管理/删除,它不会像
#table
那样自动删除,但由于它是普通表,任何连接都可以看到它。As already noted, a temporary table created with the single hash/pound
#
prefix is visible only to the connection that created it.However, there's nothing stopping you from creating a normal user table in tempDB and benefitting from the various optimisations that exist for TempDB.
Of course any table you create you'll need to manage/remove yourself, it won't be automatically removed like a
#table
would be, but as it's a normal table any connection can see it.临时表仅对创建临时表的会话可见。msdn 参考
新查询窗口是一个新会话,因此它不能引用在另一个会话中创建的临时表。
Temporary table is just visible to session that created the temporary table.msdn reference
New Query Window is a new session, so it cannot refer to the temporary table created in another session.