SQL Server Interview Topic 7: Troubleshooting and Optimization
This topic checks whether you can think calmly when SQL Server problems happen in real projects. Interviewers like practical answers with a clear investigation process.
You should be able to explain how you investigate slow queries, wrong data, missing records, duplicate records, and production issues.
Q54. How do you investigate a slow SQL query?
Quick interview answer:
First check what the query is doing, how many rows it reads, and whether filters are correct. Then check indexes and the execution plan. Also confirm whether the query returns too much data or does unnecessary joins.
Study in detail: Monitoring and Performance and Performance Case Studies - These lessons explain practical performance checks.
Q55. What are common reasons for slow queries?
Quick interview answer:
Common reasons include missing indexes, too many rows, wrong joins, functions on filtered columns, selecting unnecessary columns, and returning all data without pagination. Bad table design can also cause slow queries.
Study in detail: Indexes and Performance - This article explains how indexes affect query speed.
Q56. How do you troubleshoot missing records in a report?
Quick interview answer:
Check filters, joins, date conditions, and NULL handling. A common mistake is using INNER JOIN when LEFT JOIN is needed. Another common issue is filtering right-side table columns after a LEFT JOIN.
Study in detail: LEFT and RIGHT JOIN and NULL Handling - These lessons explain missing data scenarios.
Q57. How do you find duplicate records?
Quick interview answer:
Use GROUP BY with COUNT(*) to find repeated values. For example, group by mobile number or admission number and show only groups where count is greater than one. After finding duplicates, check business rules before deleting anything.
Study in detail: GROUP BY and HAVING - This lesson explains grouping and duplicate checks.
Q58. What is a deadlock?
Quick interview answer:
A deadlock happens when two transactions block each other and neither can continue. SQL Server chooses one transaction as the victim and rolls it back. Developers can reduce deadlocks by keeping transactions short and updating tables in a consistent order.
Study in detail: Transactions and Concurrency - This article explains locking and concurrency in simple terms.
Q59. How do you safely fix wrong production data?
Quick interview answer:
First understand the issue and take a backup or confirm restore options. Then write a SELECT query to verify affected rows before writing UPDATE or DELETE. Run the fix inside a transaction when possible and keep the script for audit.
Study in detail: Troubleshooting and Backup and Restore - These lessons explain safer production handling.
Q60. What is your basic SQL troubleshooting checklist?
Quick interview answer:
Check the requirement, sample data, filters, joins, NULL values, indexes, and execution plan. Then test with small data and compare expected output with actual output. Do not guess; isolate the problem step by step.
Study in detail: Troubleshooting - This article gives a practical debugging approach.
Practice Before Next Topic
Explain how you would troubleshoot these issues:
- Student report is missing some students.
- Search screen is slow.
- Duplicate mobile numbers exist.
- Fee payment update failed halfway.
- A report gives different counts than expected.
Troubleshooting answers should sound like a process. Say what you check first, second, and third.