Search code examples
sql-serverperformance

CTE vs View Performance in SQL Server


Which one is faster :

  1. query from a cte
  2. query from a view

(in Complex Queries). I have a complex query and i have another complex query from the first one.Is it faster to create a view for the first complex query and query from the view or use cte?


Solution

  • A view is a permanent object and the results can be indexed, while a CTE is temporary and created only when used so less flexible. It will be more efficient to break apart your complex query into indexed views than into CTE's. It will be most efficient to ensure all of the tables are properly indexed, which will probably do more for performance than worrying about views vs. CTE's.