Where Do Temporary Tables Get stored in sql server?

喜你入骨 提交于 2020-01-01 04:06:06

问题


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.


回答1:


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.




回答2:


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




回答3:


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




回答4:


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)


来源:https://stackoverflow.com/questions/3012662/where-do-temporary-tables-get-stored-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!