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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 difference betwee cte and temp table in sp

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2011-03-27 : 06:43:18
Hi,

I read a few articles but I am still confused as to the differences and advantages/disadvantage between cte and temp tables/derived tables within a stored procedure.
I will appreciate clarifications.

Thanks

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-03-27 : 07:27:30
I may be repeating what you already read, but there are some cases where you will need a CTE and some others where you will need a temp table. Then there are cases where you can use one or the other.

For example, CTE can be used only within the same select; you cannot add any indexes on CTE's etc.

On the other hand, CTE has some advantages, for example, you can use recursive CTE to accomplish some tasks that would be difficult to do otherwise; the query is usually more compact etc.

If you are trying to write a specific query, if you post the query, some of the people on this forum may be able to offer specific advice on whether temp table or CTE would be better.
Go to Top of Page
   

- Advertisement -