|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, October 28, 2005 7:13 AM
Points: 18,
Visits: 1
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:31 PM
Points: 32,921,
Visits: 26,810
|
|
Nice job and you got right to the point. Great comparison example against derived tables. My hat's off to you.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 8:55 AM
Points: 1,865,
Visits: 556
|
|
great article! CTEs were well explained and the examples demonstrated the application of CTEs effectively and succinctly. cheers.
Life: it twists and turns like a twisty turny thing
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 5:24 AM
Points: 51,
Visits: 89
|
|
I wiould urge DBA's to be mindful of places where CTEs get used, but views would provide either better performance or a resource that could be used in several places. Is there any information on the performance of a CTE vs. that of a view?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, June 10, 2008 4:30 AM
Points: 3,
Visits: 2
|
|
| good material. looking forward for more enhanced feature in sql 2005
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 10:43 AM
Points: 287,
Visits: 213
|
|
I would argue that CTEs are an excellent development tool at the very least. They might point out an area where a view might be put in place but why create a view until you need it. I would also consider using a CTE if there was only one query that needed it. If I needed it in another place I would create the view and refactor the original query to use the view instead since I would surely have used stored procedures.
Bryant E. Byrd, BSSE MCDBA MCAD Business Intelligence Administrator MSBI Administration Blog
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
|
|
Hi Bryant, I think that in sql statements where you can use CTEs as views, there exists ways of writing the CTE as an inner join or sub query. Also, I tested with a few samples and saw that there is not a notiable increase in performance. So I meant that the real reason or necessity for a CTE is not the usage of CTE instead of a view. You are right you should not need to create a view if it will be used once. But you can not also refer to a CTE for a second time. You can use it just after the definition of the CTE. But even this usage is a plus and gives developers a flexiblity in their coding processes. And I tried to mention that the real power of a CTE is visible when it is used as a recursive common table expression. Eralper http://www.kodyaz.com
Eralper SQL Server and T-SQL Tutorials and Articles Microsoft Certification and Certification Exams
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, January 03, 2013 4:53 PM
Points: 118,
Visits: 45
|
|
I can see the use of this CTE in many places. Since I don't have the sql 2005 installed, is it possible to use variables inside the CTEs? The below example is for illustration purpose only and of no practical use i think of: declare @maxcount as int set @maxcount=10 WITH TitleCount (authorID, titleCount) AS ( SELECT au_id, COUNT(title_id) FROM titleauthor GROUP BY au_id having count(title_id) <= @maxcount ) SELECT au_id, au_lname, au_fname, titleCount FROM authors a INNER JOIN TitleCount ON TitleCount.authorID = a.au_id
Thanks
|
|
|
|