简单复现:
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/