Ashish Sahu
@ashsau
SQL Interview Questions
Ashish Sahu
@ashsau
Q1. What is SQL?
SQL stands for Structured Query Language, used for managing
and manipulating relational databases.
Q2. What are the different types of SQL commands?
DDL (Data Definition Language),
DML (Data Manipulation Language),
DCL (Data Control Language),
TCL (Transaction Control Language).
Ashish Sahu
@ashsau
Q3. What is a primary key?
Function: A unique identifier for records in a table,
ensuring no duplicate values.
Q4. What is a foreign key?
Definition: A key used to link two tables, referencing the
primary key in another table.
Q5. What is a JOIN? Explain different types.
JOIN: Combines rows from two or more tables based on a
related column.
Types: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.
Ashish Sahu
@ashsau
Q6. What is normalization?
Purpose: Organizing database to reduce redundancy and
improve data integrity.
Q7. Explain ACID properties.
ACID: Atomicity, Consistency, Isolation, Durability
– ensure reliable transactions.
Ashish Sahu
@ashsau
Q8. What is a subquery?
Definition: A query nested inside another query, used to
perform complex searches.
Q9. Difference between WHERE and HAVING clauses?
WHERE: Filters rows before grouping.
HAVING: Filters groups after the grouping is done.
Q10. What is an index?
Use: A performance optimization feature that allows faster
retrieval of records.
Ashish Sahu
@ashsau
Q11. What is a view?
Definition: A virtual table based on the result of an SQL query.
Q12. What is a stored procedure?
Purpose: A precompiled collection of one or more SQL
statements for reuse.
Q13. Explain the difference between DELETE and
TRUNCATE.
DELETE: Removes specific rows, can be rolled back.
TRUNCATE: Removes all rows, cannot be rolled back.
Ashish Sahu
@ashsau
Q14. What is a trigger?
Function: A set of instructions that automatically executes in
response to certain events on a table.
Q15. Explain the difference between UNION and UNION
ALL.
UNION: Combines results of two queries and removes
duplicates.
UNION ALL: Combines results and includes duplicates.
1
1 2
1 2 3 2 No duplicate
2 3
3
Table A Table B
A UNION B
1
1 2 2 2
1 3 Duplicate
2 3 2 2
3
Table A Table B
A UNION ALL B