Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 temporary tables are stored.

like image 751
Shantanu Gupta Avatar asked Jun 10 '10 08:06

Shantanu Gupta


People also ask

Are temp tables stored in memory?

This all means that temporary tables behave like any other sort of base table in that they are logged, and stored just like them. In practice, temporary tables are likely to remain cached in memory, but only if they are frequently-used: same as with a base table.

How does SQL Server store temp data?

To create a Global Temporary Table, add the “##” symbol before the table name. Global Temporary Tables are visible to all connections and Dropped when the last connection referencing the table is closed. Global Table Name must have an Unique Table Name.


2 Answers

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.

like image 141
Giorgi Avatar answered Sep 18 '22 15:09

Giorgi


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

like image 37
Ankit Chaurasia Avatar answered Sep 18 '22 15:09

Ankit Chaurasia