Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 when to use table variable and temp table

Author  Topic 

nextaxtion
Yak Posting Veteran

54 Posts

Posted - 2014-12-21 : 10:44:30
hi team,

i need to insert some records and loop through inserted records also several dml need to perform on that on the fly. Which temp table i should use table variable or temp table.

Records count not more than 5 thousands.Also suggest me except this scenario when to use temp or derived table.



prithvi nath pandey

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-21 : 16:18:20
Use table var when either query is simple or table is small. 5000 is small enough. Depends on what you will do with it.
Go to Top of Page

nextaxtion
Yak Posting Veteran

54 Posts

Posted - 2014-12-22 : 01:37:08
why?? when data is small then temp table works bad ??? pls explain

prithvi nath pandey
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2014-12-22 : 07:51:14
Follow this link, there is a VERY good answer in the thread.
http://stackoverflow.com/questions/11857789/when-should-i-use-a-table-variable-vs-temporary-table-in-sql-server








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
   

- Advertisement -