Home > Sample chapters > Programming > SQL Server

Foundations of Querying Microsoft SQL Server 2012

Case Scenarios

In the following case scenarios, you apply what you’ve learned about T-SQL querying. You can find the answers to these questions in the Answers section at the end of this chapter.

Case Scenario 1: Importance of Theory

You and a colleague on your team get into a discussion about the importance of understanding the theoretical foundations of T-SQL. Your colleague argues that there’s no point in understanding the foundations, and that it’s enough to just learn the technical aspects of T-SQL to be a good developer and to write correct code. Answer the following questions posed to you by your colleague:

  1. Can you give an example for an element from set theory that can improve your understanding of T-SQL?

  2. Can you explain why understanding the relational model is important for people who write T-SQL code?

Case Scenario 2: Interviewing for a Code Reviewer Position

You are interviewed for a position as a code reviewer to help improve code quality. The organization’s application has queries written by untrained people. The queries have numerous problems, including logical bugs. Your interviewer poses a number of questions and asks for a concise answer of a few sentences to each question. Answer the following questions addressed to you by your interviewer:

  1. Is it important to use standard code when possible, and why?

  2. We have many queries that use ordinal positions in the ORDER BY clause. Is that a bad practice, and if so why?

  3. If a query doesn’t have an ORDER BY clause, what is the order in which the records are returned?

  4. Would you recommend putting a DISTINCT clause in every query?