SQL Server:在新查询窗口中查询临时表

发布于 2025-01-09 22:15:45 字数 351 浏览 3 评论 0原文

我使用以下脚本创建临时表

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别挽留 2025-01-16 22:15:45

如前所述,使用单个哈希/磅 # 前缀创建的临时表对创建它的连接可见。

但是,没有什么可以阻止您在 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.

温柔女人霸气范 2025-01-16 22:15:45

临时表仅对创建临时表的会话可见。msdn 参考

临时表
您可以创建本地和全局临时表。
本地临时表仅在当前会话中可见,全局临时表对所有会话可见。

新查询窗口是一个新会话,因此它不能引用在另一个会话中创建的临时表。

Temporary table is just visible to session that created the temporary table.msdn reference

Temporary Tables
You can create local and global temporary tables.
Local temporary tables are visible only in the current session, and global temporary tables are visible to all sessions.

New Query Window is a new session, so it cannot refer to the temporary table created in another session.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文