SQL 临时表位于何处?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4885905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where temp tables are located?
提问by atricapilla
If I create a temporary table using # sign:
如果我使用 # 符号创建临时表:
SELECT * INTO #temp FROM dbo.table
Where is this table located? I can't find this from tempdb.
这张桌子在哪里?我在 tempdb 中找不到这个。
采纳答案by marc_s
Those tables arecreated in your tempDB
- but the table name might not be exactly as you defined.
这些表是在您的tempDB
- 但表名可能与您定义的不完全相同。
In my case, I get:
就我而言,我得到:
#temp______________________________000000000003
Try this:
尝试这个:
SELECT * INTO #temp FROM dbo.table
SELECT * FROM tempdb.sys.tables
You should see an entry for that temp table you've just created....
您应该会看到刚刚创建的临时表的条目....
回答by Sachin Shanbhag
When you declare a temporary table, SQL Sever adds some additional characters on its name in order to provide a unique system name for it and then it stores it in tempDBin the sysobjects table. Even though you can query the temporary table with its logical name, internally is known with the exact name SQL Server has set.
当您声明临时表时,SQL Sever 在其名称上添加一些附加字符,以便为其提供唯一的系统名称,然后将其存储在 sysobjects 表中的tempDB中。尽管您可以使用其逻辑名称查询临时表,但在内部使用 SQL Server 设置的确切名称是已知的。
回答by Karel
How are you looking for them? If you do a select you'll get the data. But the table is only available in the session, just for the user who created it (you can have global temp tables).
你怎么找他们?如果您进行选择,您将获得数据。但是该表仅在会话中可用,仅供创建它的用户使用(您可以拥有全局临时表)。
They are stored in temp db.
它们存储在临时数据库中。
回答by gngolakia
Local temp tables can be created using hash (#) sign prior to table name.
可以在表名之前使用哈希 (#) 符号创建本地临时表。
They are visible only in current connection. When connection is dropped its scope ends as well.
它们仅在当前连接中可见。当连接被删除时,它的范围也会结束。
It is possible to create and use local temp table with the same name simultaneously in two different connections.
可以在两个不同的连接中同时创建和使用同名的本地临时表。
Read More
阅读更多
http://sqlnetcode.blogspot.com/2011/11/there-is-already-object-named-temp-in.html
http://sqlnetcode.blogspot.com/2011/11/there-is-already-object-named-temp-in.html
回答by Expat C
I suspect this issue rose from the fact that if you don't right click and refresh the 'Temporary Tables' folder, SSMS will not show you the temp table immediately.
我怀疑这个问题是因为如果您不右键单击并刷新“临时表”文件夹,SSMS 将不会立即向您显示临时表。