开发者

Where Do Temporary Tables Get stored in sql server?

开发者 https://www.devze.com 2023-01-02 19:08 出处:网络
Where do temporary tables get stored in a database? I want to drop a temporary table if it already exists.

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 tempora开发者_如何转开发ry tables are stored.


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.


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


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


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)


Here you can find all your temp tables (both local and global) which are stored and active using SSMS.

Where Do Temporary Tables Get stored in sql server?

0

精彩评论

暂无评论...
验证码 换一张
取 消