临时表存储在 sql server 中的什么位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3012662/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:30:13  来源:igfitidea点击:

Where Do Temporary Tables Get stored in sql server?

sqlsql-server-2005temp-tables

提问by Shantanu Gupta

Where do temporary tables get stored in a database? I want to drop a temporary table if it already exists. I can do this for securable tables by querying at information schema but I don't know where temporary tables are stored.

临时表存储在数据库中的什么位置?如果临时表已经存在,我想删除它。我可以通过查询信息模式来为安全表执行此操作,但我不知道临时表的存储位置。

回答by Giorgi

Temporary tables are stored in tempdb Database. There are various ways to check if a temp table exists outlined here: Check If Temporary Table Exists.

临时表存储在tempdb 数据库中。此处概述了检查临时表是否存在的各种方法:检查临时表是否存在

回答by Ankit Chaurasia

Temporary tables gets stored in tempdb database which is present in SystemDatabase or SystemDatabase -> tempdb -> Temporary Tables

临时表存储在存在于 SystemDatabase 或 SystemDatabase -> tempdb -> Temporary Tables 中的 tempdb 数据库中

回答by sanjay

TempDb Will In in SystemDatabase.Temp tables are stored here.

TempDb 将在 SystemDatabase.Temp 表中存储在这里。

回答by Gurung

Store at this table

存放在这张桌子上

SELECT *
FROM   tempdb.sys.tables

Delete query:

删除查询:

DECLARE @sql NVARCHAR(MAX)
SELECT @sql = ISNULL(@sql + ';', '') + 'drop table ' + QUOTENAME(NAME)
FROM   tempdb..sysobjects
WHERE  NAME LIKE '#%'

EXEC (@sql)