Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:38:50+00:00 2026-05-26T06:38:50+00:00

Do CTEs use any space in tempdb or does it use memory exclusively? I’ve

  • 0

Do CTEs use any space in tempdb or does it use memory exclusively?

I’ve tagged the question with both mssql 2005 and 2008 as I use both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:38:51+00:00Added an answer on May 26, 2026 at 6:38 am

    I’ll try not to copy/paste MSDN

    It doesn’t matter.

    A CTE is independent of query execution: it is only a language construct. Think of it as neat derived table or subquery.

    This means that except for recursive CTEs (see later), all CTEs can be coded inline. If you use the CTE code once, it is for readability. If you use the CTE twice or more, then it is defensive: you don’t want to make a mistake and have the derived table different each use.

    Where a CTE is used twice or more, then that code will be executed twice or more. It won’t be executed once and cached in tempdb.

    Summary: it may or may not, just like if the code was inline.

    Note: a recursve CTE is simply a derived table inside a derived table inside a derived table inside a a derived table inside a der… so same applies.

    You can see this in Tony Rogerson’s article. The use of tempdb would happen anyway if coded inline. He also notes that using a temp table can be better because of the “macro” expansion I explained above

    FYI: the same applies to views. Just macros.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As we all know, CTEs were introduced in SQL Server 2005 and the crowd
Using MSSQL 2005 I am used to writing a statement like this: delete from
Input @StartDate = '01/25/2010' @EndDate = '02/06/2010' I have 2 CTEs in a stored
I recently learned about CTE's in SQL Server and am attempting to use it
I think I've got the format of Recursive CTEs down well enough to write
I have huge query on my SQL 2005 Server. This have to be run
I have CTEs which all uses NOLOCK inside. But then selects from those CTEs
Few days ago I have asked a question about 1,2 and 3. degree connections.
although I've been using simple CTEs in SQL Server Development I've not been able
How does writing SQL queries for reports, which often are just run once a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.