SQL SERVER – An Important Part of Most SELECT statement – WHERE clause – Quiz – Puzzle – 4 of 31

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

Writing a WHERE clause has been the easiest thing. Most of the time, we learn doing this as a basic lesson in SQL. Many times, I frequently see a simple question asking where one has to write a WHERE clause. This brings many to either failure or just plain confusion. Let us see how many different ways you can write the following WHERE clause-related question:

Notes of Vinod Kumar

No developer can work inside SQL Server and not perform a SELECT query without a WHERE clause. This is a basic requirement to become a successful programmer. The usages of clauses can be simple and complex as possible. In this context, it is also worth reading some content around short-circuiting for query.

Notes of Pinal Dave

The WHERE clause is indeed crucial in any query. I have seen many accident scenarios where a developer forgot to mention the WHERE clause and an innocent-looking query was then turned into a very dangerous query. If the DELETE statement is executed without the WHERE clause, and if deleting a complete table is not intended, there will be some disaster recovery needed to be done for sure. At that point in time, the recovery will be likely used to rollback the database to the pre-disaster moment. A SELECT statement without a WHERE clause can lead to a table scan, which is surely not desired if you want to achieve optimal performance.

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.