TSQL interview questions you ask [closed]

Posted on

TSQL interview questions you ask [closed] – This article will take you through the common SQL errors that you might encounter while working with sql, sql-server,  tsql. The wrong arrangement of keywords will certainly cause an error, but wrongly arranged commands may also be an issue. SQL keyword errors occur when one of the words that the SQL query language reserves for its commands and clauses is misspelled. If the user wants to resolve all these reported errors, without finding the original one, what started as a simple typo, becomes a much bigger problem.

SQL Problem :

Google search turns up some links to tsql questions. I was wondering what would SO experts would ask in an interview for TSQL.

Solution :

Here are some of the most common questions I’ve been asked as an ASP.Net developer with strong SQL Server skills:

  • Name and describe the different kinds of JOINs
  • What is COALESCE?
  • Explain primary and foreign keys
  • What would you do to optimize slow-running queries?
  • What is the difference between DELETE and TRUNCATE?

There are a bunch of questions here: SQL Server Quiz, Can You Answer All These?

A biggie is of course how can you code to minimize deadlocks

Take the code below for example, 80% of people get that wrong

What will be the output of the following?


In SQL query section (to extend DOK):

  • How would you handle NULL problems? (ie. NULL – 25 = ?)
  • Variations for CASE in SELECTs (pros/cons)
  • User function vs. stored procedure performance
  • .NET/SQL integration (pros/cons)
  • How would you and why chain SQL queries? (via god-query, view, stored procedures etc.)

A partial list of suggestions:

  • get the most awful SQL you’ve run across and get the candidates to explain as many things wrong with it as they can

  • ask them how they would get the query plan for the tsql they write and what are some of the things to avoid in query plans (and how they would rectify them if the did pop up); see if they know what a full table or index scan is

  • ask them if they understand how the server’s optimizer works and how that might have bearing on the tsql they write

  • ask them for a examples of when it is good to use tempdb

  • see if they know which sql clauses will force the use of tempdb behind the scenes; see if they know why this is important

  • ask them for examples of when it is better not to use a cursor

  • ask them how to ensure updates in place; ask them which vendors support that and which implement updates as delete/insert

  • have them explain why it is bad practice to use select * in code

Here are some of questions I can come up with.

  • How to implement Row_Number without using Row_Number() function.
  • How to calculate running total
  • How to transpose records – pivoting.
  • Filtering NULL records in WHERE clause
  • Conditional record ordering and filtering

Name the TRANSACTION ISOLATION LEVEL’s Explain each of them, Which is the default

I always ask programmers (not really db programmers, but programmers that shoud be able to write a DAL)

“Epxlain the difference between a subquery that is correlated and one that is not”

I know for people who know a thing or 2 about sql this sounds very easy, but to my amazement, much less than 50% gets it right.

What’s the difference between a WHERE clause and a HAVING clause?

It’s a seemingly easy question that many people get wrong, and listening to them try to answer will give you some insight into their understanding of grouping.

Finding SQL syntax errors can be complicated, but there are some tips on how to make it a bit easier. Using the aforementioned Error List helps in a great way. It allows the user to check for errors while still writing the project, and avoid later searching through thousands lines of code.

Leave a Reply

Your email address will not be published. Required fields are marked *