SQL Server (T-SQL) interview questions
LiveT-SQL, indexing, execution plans, isolation and the tuning questions SQL Server shops ask.
Subtopics
- Joins10
- Aggregates & GROUP BY/HAVING10
- Window functions10
- CTEs10
- Indexes & seeks vs scans10
- Execution plans10
- Transactions & isolation levels10
- Deadlocks10
- Normalization10
- Stored procedures10
- NULL semantics10
- Query tuning10
Sample questions
- CodingJuniorAggregates & GROUP BY/HAVING
Table
sales(id, region, amount).For every region that appears in the table, return how many sales it has and the sum of their amounts. Columns:
region,sale_count, - CodingJuniorAggregates & GROUP BY/HAVING
Table
page_views(id, page, visitor). The same visitor can view the same page many times, andvisitoris NULL when the view came from an anonymous session. - CodingJuniorAggregates & GROUP BY/HAVING
Table
exam_results(id, student, subject, score). Every student registered for a subject has a row;scoreis NULL when the student did not actually sit the exam. - TheoryJuniorAggregates & GROUP BY/HAVING
What is the difference between
WHEREandHAVING? Can a query need both at the same time? - TheoryJuniorAggregates & GROUP BY/HAVING
Explain the difference between
COUNT(*),COUNT(column)andCOUNT(DISTINCT column). Which of them can return a smaller number than the others, and why? - CodingJuniorCTEs
Tables
customers(id, name)andorders(id, customer_id, total).Compute each customer's total spend, then return only the customers whose spend is strictly greater than the average spend across all customers who