Can somebody explain me the difference between Temp table and table variable in SQL server 2005?
-
1please try a search....there are numerous articles out there...Mitch Wheat– Mitch Wheat2010-01-06 08:43:01 +00:00Commented Jan 6, 2010 at 8:43
-
Thanks.. I ve searched and got lot of answers.Prasad– Prasad2010-01-06 08:49:56 +00:00Commented Jan 6, 2010 at 8:49
-
stackoverflow.com/questions/1597309/…adrianbanks– adrianbanks2010-01-06 10:01:13 +00:00Commented Jan 6, 2010 at 10:01
4 Answers
There are few differences you can check them here. There is a performance difference that favors table variables because temporary tables prevent precompilation of procedures. Also the scope of a table variable is the same as the scope of variables compared to temporary tables which have bigger lifespan. In general table variables are the better choice in most cases.
Comments
fundamentally, temp table is written to disk until you call drop table and table variable lives in memory for the scope of the query.
Table variable is often said to be fast, but as this question of my highlight, this can be a complex subject.
1 Comment
This is a good article on SQL Server Central detailing the differences and limitations of each.