title: When should I use a table variable vs temporary table in sql server?
body: <p>I'm learning more details in table variable. It says that temp tables are always on disk, and table variables are in memory, that is to say, the performance of table variable is better than temp table because table variable uses less IO operations than temp table.</p>
  
  <p>But sometimes, if there are too many records in a table variable that can not be contained in memory, the table variable will be put on disk like the temp table.</p>
  
  <p>But I don't know what the "too many records" is. 100,000 records? or 1000,000 records? How can I know if a table variable I'm using is in memory or is on disk? Is there any function or tool in SQL Server 2005 to measure the scale of the table variable or letting me know when the table variable is put on disk from memory?</p>