Friday, May 4, 2012

Facts about Temporary table and table variables.


·          Both  are stored in TempDB.
      Most o people think table variables does not store in database anywhere.
·          Temporary table will have better performance compared to table variables why because sql server uses statistics while working with the queries which contains Temporary tables but this would not happen for table variables.
      Table variables will get expired once the execution is done but Temporary tables exist till the current session is closed
·         In functions we cannot use temporary tables If you use you will get compilation errors. In this case we need to go with table variables.
      In dynamic queries also we cannot use table variables but we can use temporary tables.
·         Guide lines says that it is better to use table variables if the data is minimal. If your query is dealing with large amount of data it is better to go ahead with Temporary tables why because we will benefit from the statistics and we can create indexes on temporary tables if required.

No comments:

Post a Comment