sql interview questions, Cheat Sheet of Computer science

Sql interview questions ,which everyone need to know

Typology: Cheat Sheet

2025/2026

Available from 06/17/2026

sathvika-mannem
sathvika-mannem 🇮🇳

3 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Top 30 SQL Interview Questions and Answers
1. What is SQL?
SQL (Structured Query Language) is used to communicate with databases. It lets you create, read,
update, and delete data (CRUD operations).
2. What are the types of SQL statements?
1. DDL (Data Definition Language): CREATE, ALTER, DROP 2. DML (Data Manipulation
Language): INSERT, UPDATE, DELETE 3. DCL (Data Control Language): GRANT, REVOKE 4.
TCL (Transaction Control Language): COMMIT, ROLLBACK 5. DQL (Data Query Language):
SELECT
3. Difference between DELETE, TRUNCATE, and DROP?
DELETE: Removes rows one by one (can use WHERE). TRUNCATE: Removes all rows, resets
identity, faster. DROP: Removes the entire table structure.
4. What is a Primary Key?
A primary key uniquely identifies each record in a table. It cannot have NULL or duplicate values.
5. What is a Foreign Key?
A foreign key links two tables and enforces referential integrity between them.
6. Difference between WHERE and HAVING?
WHERE filters rows before grouping. HAVING filters groups after aggregation.
7. What are Joins?
Joins combine data from multiple tables based on related columns. Types: INNER, LEFT, RIGHT,
FULL, CROSS JOIN.
8. What is Normalization?
Normalization organizes data to reduce redundancy. Forms: 1NF, 2NF, 3NF, BCNF.
9. What is Denormalization?
The process of adding redundancy to improve read performance.
10. What is an Index?
Indexes improve query speed but slow down insert/update. Clustered index sorts actual data;
non-clustered stores pointers.
11. What are Views?
Views are virtual tables based on queries. They don’t store data physically.
pf3

Partial preview of the text

Download sql interview questions and more Cheat Sheet Computer science in PDF only on Docsity!

Top 30 SQL Interview Questions and Answers

1. What is SQL?

SQL (Structured Query Language) is used to communicate with databases. It lets you create, read, update, and delete data (CRUD operations).

2. What are the types of SQL statements?

  1. DDL (Data Definition Language): CREATE, ALTER, DROP 2. DML (Data Manipulation Language): INSERT, UPDATE, DELETE 3. DCL (Data Control Language): GRANT, REVOKE 4. TCL (Transaction Control Language): COMMIT, ROLLBACK 5. DQL (Data Query Language): SELECT 3. Difference between DELETE, TRUNCATE, and DROP?

DELETE: Removes rows one by one (can use WHERE). TRUNCATE: Removes all rows, resets identity, faster. DROP: Removes the entire table structure.

4. What is a Primary Key?

A primary key uniquely identifies each record in a table. It cannot have NULL or duplicate values.

5. What is a Foreign Key?

A foreign key links two tables and enforces referential integrity between them.

6. Difference between WHERE and HAVING?

WHERE filters rows before grouping. HAVING filters groups after aggregation.

7. What are Joins?

Joins combine data from multiple tables based on related columns. Types: INNER, LEFT, RIGHT, FULL, CROSS JOIN.

8. What is Normalization?

Normalization organizes data to reduce redundancy. Forms: 1NF, 2NF, 3NF, BCNF.

9. What is Denormalization?

The process of adding redundancy to improve read performance.

10. What is an Index?

Indexes improve query speed but slow down insert/update. Clustered index sorts actual data; non-clustered stores pointers.

11. What are Views?

Views are virtual tables based on queries. They don’t store data physically.

12. Difference between UNION and UNION ALL?

UNION removes duplicates; UNION ALL keeps duplicates.

13. What are Aggregate Functions?

SUM, COUNT, AVG, MIN, MAX — used to summarize data.

14. What is a Subquery?

A query inside another query. Used to filter or compare results dynamically.

15. What is a CTE (Common Table Expression)?

A temporary result set defined using WITH, used for readability and recursion.

16. What are Window Functions?

Functions like ROW_NUMBER(), RANK(), DENSE_RANK() perform calculations over partitions without collapsing rows.

17. Find 2nd highest salary?

SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);

18. What is a Stored Procedure?

A precompiled group of SQL statements that can be executed repeatedly.

19. What is a Trigger?

A trigger automatically executes on INSERT, UPDATE, or DELETE events.

20. What are ACID properties?

Atomicity, Consistency, Isolation, Durability — ensure reliable transactions.

21. Difference between Clustered and Non-Clustered Index?

Clustered sorts data physically; Non-clustered stores index separately with pointers.

22. What is Query Optimization?

The process of improving query performance by using indexes, avoiding subqueries, etc.

23. How to find duplicates in a table?

SELECT column_name, COUNT() FROM table GROUP BY column_name HAVING COUNT() > 1;

24. What is Self Join?

A table joined with itself using alias names to compare rows within the same table.