whats the difference between the two types of temp tables @tmp vs #tmp in SQL 2005?
and are their other types i am unaware of?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
#tmpis a temp table and acts like a real table mostly. It can have indexes, can have statistics, participates in transactions, optimiser will work out correct row estimates@tmpis a table variable. No indexes, no statistics, not transaction aware, optimiser always assumes exactly 1 rowOtherwise, they are both scoped (slightly different), in memory/cache but context is tempdb though, will spill to disk if too big etc
Edit:
About keys on table variables. They make no difference. There are no stats and one row is assumed. It will change a table scan to a clustered index scan which is the same. Check any query plan and estimated rows.
Also, just read this Read What a difference a temp table makes over a table variable