Mid
T-SQL
SQL & Databases
Explain temp tables vs table variables vs CTEs for interview queries.
Short answer: CTEs are named query scopes (not persisted). Temp tables (#t) live in tempdb, support indexes/statistics, good for larger intermediate sets. Table variables (@t) are lighter but historically weaker stats — fine for small sets. Choose based on size and reuse.
Do not claim CTEs are always “faster” — they are about readability/recursion first.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png