sql-server - 为什么可以有没有名字的临时表?

标签 sql-server sql-server-2012

简单复现:

SELECT ProductID
INTO #
FROM dbo.Products;

SELECT *
FROM #;

IF OBJECT_ID('tempdb..#') IS NOT NULL
    PRINT 'Wow';

这执行得很好,结果我感到

为什么/怎么可能?

没有名字不能有实表,为什么临时表可以无名?

最佳答案

您的临时表不是无名的。它的名字是“#”。

Local Temp Table
Local temp tables are only available to the current connection for the user; and they are automatically deleted when the user disconnects from instances. Local temporary table name is started with hash ("#") sign.

简而言之,文档说它必须以哈希开头。但没有其他限制(即长度)。

这同样适用于以两个散列字符开头的全局临时表。

更多信息在这里:http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005

关于sql-server - 为什么可以有没有名字的临时表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33144493/

相关文章:

c# - 无法加载文件或程序集 'Microsoft.VisualStudio.Data.Tools.SqlEditor.dll'

sql - 更改聚集索引列

asp.net - 错误: “A field or property with the name was not found on the selected data source” get only on server

sql-server - 每天只运行一次的触发器

SQL 2008 VS 2012错误: Incorrect syntax near the keyword 'COMPUTE'

sql - 如何从 SQL Server 读取 JSON 数据?

sql - 如何识别重复记录的唯一标识符?

c# - 更改从asp.net中的sql查询接收到的文本

Android 应用程序离线同步到 Azure SQL Server 和 Blob 存储

SQL Server 给出语法错误