Are table variables created in memory or in tempdb? Same for short temp tables?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
In MS SQL 2014 was introduced special type of table variables "Memory-Optimized Table Variables". And they don't use tempdb.
See https://msdn.microsoft.com/en-us/library/dn535766.aspx
A temp table will be created in tempdb and you can easily check for it by querying the sysobjects table in tempdb
example
you should see something with a name like #test_______000000000905 but then with more underscores
If you need to check if a temp table exists then see also How Do You Check If A Temporary Table Exists In SQL Server
The structure of Table variable is also created in tempdb To see the table variable you could do something like this but there is not guarantee that someone didn't sneak in before you when creating his/her table variable. The table variable name will be something like #7BB1235D
For more info see here: http://support.microsoft.com/kb/305977
It's been my understanding that, at a minimum, the structure of a table variable is always created in TempDB. Then, as pointed out by SQLMenace, the data may or may not spill over.
Per this Microsoft Knowledge Base Article: