

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Sql interview questions ,which everyone need to know
Typology: Cheat Sheet
1 / 3
This page cannot be seen from the preview
Don't miss anything!


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?
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.