Where Do Temporary Tables Get stored in sql server?
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.
精彩评论