Here are some important SQL interview questions that are commonly asked in interviews.
These cover a variety of topics, ranging from basic to advanced concepts:
1. What is SQL?
 • Answer: SQL (Structured Query Language) is a standard language used to
 communicate with relational databases. It is used to perform tasks like querying,
 updating, inserting, and deleting data, as well as managing database structures.
2. What are the different types of SQL commands?
 • Answer:
 o DDL (Data Definition Language): CREATE, ALTER, DROP
 o DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE
 o DCL (Data Control Language): GRANT, REVOKE
 o TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
3. What is the difference between INNER JOIN and OUTER JOIN?
 • Answer:
 o INNER JOIN: Returns rows that have matching values in both tables.
 o OUTER JOIN: Returns all rows from one table and the matching rows from the
 other table. If no match exists, the result will include NULL values for non-
 matching rows. Outer joins can be further classified as:
 ▪ LEFT OUTER JOIN (LEFT JOIN)
 ▪ RIGHT OUTER JOIN (RIGHT JOIN)
 ▪ FULL OUTER JOIN
4. What is normalization? What are the different normal forms?
 • Answer: Normalization is the process of organizing a database to reduce redundancy
 and dependency by dividing large tables into smaller ones and defining relationships
 between them. The different normal forms are:
 o 1NF (First Normal Form): Eliminate repeating groups; each column must
 contain atomic values.
 o 2NF (Second Normal Form): Meet 1NF and remove partial dependencies.
 o 3NF (Third Normal Form): Meet 2NF and remove transitive dependencies.
 o BCNF (Boyce-Codd Normal Form): A stricter version of 3NF.
 o 4NF (Fourth Normal Form): Meet 3NF and eliminate multi-valued
 dependencies.
5. What is a primary key and a foreign key?
 • Answer:
 o Primary Key: A unique identifier for each record in a table. A table can have
 only one primary key, and it cannot have NULL values.
 o Foreign Key: A column or group of columns in one table that refers to the
 primary key in another table. It is used to establish a relationship between
 two tables.
6. What is the difference between DELETE, TRUNCATE, and DROP?
 • Answer:
 o DELETE: Removes rows from a table but does not remove the table structure.
 It can be rolled back if used with a transaction.
 o TRUNCATE: Removes all rows from a table and frees the space associated
 with the table. It cannot be rolled back and does not log individual row
 deletions.
 o DROP: Removes a table or database from the database system entirely,
 including its structure.
7. What is an index in SQL?
 • Answer: An index is a database object used to improve the speed of data retrieval
 operations on a table. It creates a pointer to the data in a table, similar to the index
 in a book. There are two types:
 o Clustered Index: The data in the table is physically ordered based on the
 index.
 o Non-clustered Index: A separate structure that points to the actual data.
8. What is a subquery?
 • Answer: A subquery is a query within another query. It is used to retrieve data that
 will be used in the main query. Subqueries can be used in SELECT, INSERT, UPDATE,
 and DELETE statements.
9. What is a GROUP BY clause and how does it work?
 • Answer: The GROUP BY clause groups rows that have the same values in specified
 columns into summary rows, like "count", "sum", "average". It is often used with
 aggregate functions like COUNT(), SUM(), AVG(), MAX(), and MIN().
10. What are aggregate functions in SQL?
 • Answer: Aggregate functions perform a calculation on a set of values and return a
 single value. Examples include:
 o COUNT()
 o SUM()
 o AVG()
 o MIN()
 o MAX()
11. What is the difference between HAVING and WHERE clause?
 • Answer:
 o WHERE: Filters rows before grouping (used with individual rows).
 o HAVING: Filters groups after the GROUP BY clause is applied (used with
 aggregated results).
12. What is a UNION operator?
 • Answer: The UNION operator is used to combine the result sets of two or more
 SELECT statements. It removes duplicate rows by default. Use UNION ALL if you want
 to include duplicates.
13. What is the difference between UNION and JOIN?
 • Answer:
 o UNION: Combines the results of two or more SELECT queries into one result
 set, stacking rows vertically.
 o JOIN: Combines columns from two or more tables based on a related column
 between them, combining data horizontally.
14. What are the different types of constraints in SQL?
 • Answer: Constraints are used to enforce rules on data in a table. Common types of
 constraints include:
 o NOT NULL
 o PRIMARY KEY
 o FOREIGN KEY
 o UNIQUE
 o CHECK
 o DEFAULT
15. What is a transaction in SQL?
 • Answer: A transaction is a sequence of one or more SQL operations that are
 executed as a single unit. A transaction ensures that the operations are completed
 successfully, and if an error occurs, it can be rolled back. Transactions are controlled
 using COMMIT, ROLLBACK, and SAVEPOINT.
16. What is a VIEW in SQL?
 • Answer: A VIEW is a virtual table that is based on the result of a SELECT query. It
 does not store data physically but provides a way to access data from one or more
 tables.
17. What is a stored procedure?
 • Answer: A stored procedure is a precompiled collection of one or more SQL
 statements that can be executed as a single unit. It can accept input parameters,
 execute operations, and return results.
18. What is the difference between CHAR and VARCHAR?
 • Answer:
 o CHAR: A fixed-length data type. If the string is shorter than the defined
 length, it will be padded with spaces.
 o VARCHAR: A variable-length data type. It only uses as much space as
 necessary for the string.
19. Explain the concept of ACID properties.
 • Answer: ACID stands for:
 o Atomicity: Ensures that all operations in a transaction are completed
 successfully, or none are applied.
 o Consistency: Ensures that the database remains in a consistent state before
 and after a transaction.
 o Isolation: Ensures that transactions are isolated from each other, meaning
 one transaction's operations are not visible to others until completed.
 o Durability: Ensures that once a transaction is committed, it will remain in the
 database even in case of a failure.
20. What is a trigger in SQL?
 • Answer: A trigger is a set of SQL statements that are automatically executed or
 "triggered" by certain events on a particular table or view, such as INSERT, UPDATE,
 or DELETE.
These questions cover fundamental SQL concepts and will give you a solid foundation for
interviews. Be prepared to explain your answers in depth and provide examples where
possible