21. What is a Covering Index?
Answer: An index that contains all the columns needed to satisfy a query without accessing the base table (reduces IO).
Example: CREATE NONCLUSTERED INDEX idx_Covering
ON Employees (Name, DepartmentID, Salary);
22. Explain Database Mirroring.
Answer: A disaster recovery feature to keep two copies of a database synchronized (Principal and Mirror server).
23. What is Change Data Capture (CDC)?
Answer: A feature to track changes (INSERT, UPDATE, DELETE) in tables automatically.
Example:
EXEC sys.sp_cdc_enable_table
@source_schema = ‘dbo’,
@source_name = ‘Employees’,
@role_name = NULL;
24. What is Change Tracking?
Answer: Lightweight alternative to CDC — only tells that a change happened, not what changed.
Example:
25. What are Window Functions?
Answer: Functions that perform calculations across a set of table rows related to the current row.
Example:
26. Difference between DELETE and TRUNCATE?
Answer:
DELETE | TRUNCATE |
---|---|
Row-by-row deletion | Deallocates entire data pages |
Can use WHERE clause | Cannot use WHERE |
Slower | Faster |
Triggers fire | No triggers fire |
27. What are Indexed Views Limitations?
Answer:
-
Restrictions like:
-
No outer joins,
-
No aggregates like DISTINCT,
-
Must be schema-bound,
-
Columns must be deterministic.
-
28. Explain the FOR JSON clause in SQL Server.
Answer: Generates JSON output from SQL query results.
Example: SELECT Name, Salary
FROM Employees
FOR JSON AUTO;
29. What is MERGE Statement?
Answer: A single statement to Insert, Update, or Delete based on conditions.
Example:
30. Explain Error Handling with TRY…CATCH.
Answer: Handle errors inside SQL batches, procedures, or triggers.
Example:
1 thought on “Top 50 Advanced SQL Questions asked in Top Companies (with Answers + Examples)”