Google search turns up some links to tsql questions. I was wondering what would SO experts would ask in an interview for TSQL.
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?
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.)
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.
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
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?
SELECT 3/2
Name the TRANSACTION ISOLATION LEVEL's Explain each of them, Which is the default ?
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
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.