Top SQL Interview Questions and Answers (2025)

Prepare for your SQL interview rounds with these top questions and clear, concise answers. This guide covers SQL queries, joins, indexing, and database concepts, ideal for freshers and experienced candidates.

SQL Interview Questions and Answers

1. What is SQL?
Structured Query Language used to manage and manipulate relational databases.

2. What are the different types of SQL statements?
DDL, DML, DCL, and TCL.

3. What is a primary key?
A column that uniquely identifies each row in a table.

4. What is a foreign key?
A key used to link two tables together.

5. Explain normalization.
The process of organizing data to reduce redundancy.

6. What is denormalization?
Introducing redundancy to improve read performance.

7. What is an index in SQL?
A database object that improves the speed of data retrieval.

8. What is a join in SQL?
Combining rows from two or more tables based on related columns.

9. Types of joins in SQL?
INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.

10. What is an INNER JOIN?
Returns records with matching values in both tables.

11. What is a LEFT JOIN?
Returns all records from the left table and matching records from the right.

12. What is a RIGHT JOIN?
Returns all records from the right table and matching records from the left.

13. What is a FULL JOIN?
Returns all records when there is a match in either table.

14. What is a view in SQL?
A virtual table based on SQL queries.

15. What is a stored procedure?
A set of SQL statements stored and executed on the database server.

16. What is a trigger in SQL?
A procedure that automatically executes in response to certain events on a table.

17. What is a unique key?
Ensures all values in a column are unique, allowing one NULL.

18. Difference between primary key and unique key?
Primary key doesn’t allow NULLs; unique key allows one NULL.

19. What is a composite key?
A combination of two or more columns used as a primary key.

20. What is SQL injection?
A security vulnerability where attackers execute malicious SQL statements.

21. How to prevent SQL injection?
Use prepared statements and parameterized queries.

22. What is a subquery?
A query nested inside another query.

23. What is a correlated subquery?
A subquery that uses values from the outer query.

24. What is GROUP BY?
Used to group rows that have the same values in specified columns.

25. What is HAVING clause?
Used to filter groups after GROUP BY.

26. What is the difference between WHERE and HAVING?
WHERE filters before grouping; HAVING filters after grouping.

27. What is an aggregate function?
Functions that perform calculations on multiple values, like COUNT, SUM, AVG.

28. What is the use of COUNT()?
Returns the number of rows that match a specified condition.

29. Explain the use of DISTINCT.
Removes duplicate records from the result set.

30. What is a transaction in SQL?
A sequence of operations performed as a single logical unit of work.

31. What are ACID properties?
Atomicity, Consistency, Isolation, Durability.

32. What is a cursor in SQL?
Used to retrieve, manipulate, and navigate through result sets row by row.

33. What is the difference between DELETE and TRUNCATE?
DELETE removes rows with conditions; TRUNCATE removes all rows without logging each row.

34. What is the difference between DROP and TRUNCATE?
DROP removes the table structure; TRUNCATE removes data but keeps the structure.

35. What is a schema in SQL?
A logical container for database objects like tables and views.

36. What is a database?
An organized collection of structured information.

37. How to fetch the first 5 rows from a table?
Using LIMIT 5 in MySQL or FETCH FIRST 5 ROWS ONLY in SQL Server.

38. What is the BETWEEN operator?
Selects values within a given range.

39. What is the LIKE operator used for?
Used for pattern matching in queries.

40. What are wildcards in SQL?
Symbols like % and _ used with LIKE for pattern matching.

41. What is a NULL value in SQL?
Represents missing or undefined data.

42. How to check for NULL values in SQL?
Using IS NULL or IS NOT NULL.

43. What is the COALESCE function?
Returns the first non-NULL value in a list.

44. How to update data in SQL?
Using the UPDATE statement with SET and WHERE clauses.

45. How to delete data in SQL?
Using the DELETE statement with a WHERE clause.

46. How to insert data in SQL?
Using the INSERT INTO statement.

47. What is indexing in SQL?
Improves the speed of data retrieval operations on a table.

48. What are the types of indexes?
Clustered and non-clustered indexes.

49. What is a clustered index?
Sorts and stores the data rows in the table based on key values.

50. What is a non-clustered index?
Creates a separate structure to hold index data pointing to the actual table rows.

Frequently Asked Questions

  1. What skills are needed for SQL roles?

    Query writing, database design, normalization, indexing, and performance tuning.

  2. How to prepare for an SQL interview?

    Practice writing queries, understand joins, indexing, normalization, and real-world scenarios.

  3. Why choose a career in SQL/database roles?

    SQL skills are in demand for data-driven decision-making, ETL, and backend development careers.