SQL Interview Questions and Answers Final PDF
SQL Interview Questions and Answers Final PDF
WHERE: Filters rows before grouping. Used with SELECT, UPDATE, DELETE.
HAVING: Filters groups after aggregation. Used with GROUP BY.
Types:
Single-row subquery
Multi-row subquery (IN, ANY, ALL)
Correlated subquery: Uses outer query column.
7. What is normalization? Explain 1NF to 3NF.
Normalization organizes data to remove redundancy.
✅ Pros:
❌ Cons:
ACID:
A trigger is a stored procedure that automatically runs in response to certain events on a table
22. What is the difference between INNER JOIN and OUTER JOIN?
❌ Avoid indexing:
Small tables
Columns with frequent INSERT/UPDATE
Columns with low cardinality (e.g., gender)
Use:
View using:
Create indexes
Avoid SELECT *
Use joins efficiently
Minimize subqueries
Avoid functions on indexed columns
Analyze execution plan
Limit rows using TOP, OFFSET-FETCH
One-to-One
One-to-Many (most common)
Many-to-Many (requires a junction table)
48. What is the difference between TRUNCATE and DELETE with no WHERE?
✅ Prevention:
53. What is the difference between REPLACE() and STUFF() in SQL Server?
60. How do you find all tables that contain a specific column in SQL Server?
📌 Difference:
UNION: Combines rows from multiple result sets vertically (same structure)
JOIN: Combines rows horizontally based on relationships
81. How do you update data in one table based on another table?
92. What is the difference between TEMPDB, MASTER, MODEL, and MSDB databases?
System DB Purpose
MASTER Tracks server-level info (logins, linked servers)
TEMPDB Stores temporary tables, temp vars, intermediate results
MODEL Template for new databases
MSDB Manages jobs, alerts, scheduling (SQL Agent)
📌 Requirements:
WITH TIES: Includes additional rows with the same value as the last row.
99. What is a blocking vs deadlock?
✅ Deadlocks are fatal (one gets killed), blocking just causes delay.