Year 2011 was a year of learning and opportunity for me. My recent book, SQL Server Interview Questions and Answers, has received such overwhelming love and support from all of you. While writing the book, I had two simple goals: (1) Master the Basics and (2) Ignite Learning. There was a constant request from the Community to take the learning of these books to the next level. Here is an article which discusses the Author’s Perspective.

Beyond Relational has come up with a very interesting concept – they have converted a few of the questions from my book intotheSQL Quiz. The quiz is indeed focused on my two goals. In addition, it’s going to put the learning of the book to a higher stage. Looking at this novel concept, Vinod Kumar (Co-author) and I have decided to help every participant and reader by giving a few hints and suggestions to solve the quiz.

SQL Quiz

As part of performance tuning exercises, our developer always suggest to use SET based operations rather than procedural languages. One of the suggestions given as a substitute for hierarchical data structure was to use CTE. What are CTEs inside SQL Server, what are their advantages and how can you rewrite a subquery using CTEs?

Notes of Vinod Kumar

Common Table Expressions a.k.a CTEs are an important addition to SQL Server. Though CTE is available as an alternative for Views, Subqueries, there is a special case scenario for using CTEs. Tell us, how innovatively have you used CTEs? Can there be recursive CTEs? If yes, have you ever tried them?

Notes of Pinal Dave

CTEs are often confused with Temp Table and Subqueries, but there are more facts about this subject. While working with recursive CTEs, one has to make sure that they do not go into an infinite loop and stop after certain numbers of fixed iteration. SQL Server does have an option to limit the numbers of iteration; however, there is a default number which is associated with number of loops. CTEs are also very useful in terms of readability. I’ve started to use CTEs in many places, but before I began to practice CTEs, I made sure that I’d spend a good amount of time to learn about them, and so I did.

Pinal Dave is a technology enthusiast and an independent consultant. He has authored 11 SQL Server database books, 21 Pluralsight courses and have written over 3800 articles on the database technology on his blog at a http://blog.sqlauthority.com. Along with 14+ years of hands on experience he holds a Masters of Science degree and a number of database certifications. For any SQL Server Performance Tuning Issue send email at pinal @ sqlauthority.com .

Nupur Dave is a social media enthusiast and and an independent consultant.