SQL and Database Questions (Fresher)
Interview Zone: SQL & Database Interview Preparation
Top 30+ SQL and Database Interview Questions for Freshers
If you want to ace your first IT job, then practicing these SQL and database interview questions for freshers will help you immensely. Moreover, this guide covers queries, normalization, indexing, and more—everything freshers need to learn. In addition, we group questions into easy, medium, and advanced levels to ensure balanced preparation.
Easy SQL and Database Interview Questions for Freshers
1. What is SQL?
SQL stands for Structured Query Language. Developers use it to manage and manipulate relational databases. For example, they run queries to retrieve or update data.
2. What are the basic SQL commands?
SQL includes commands like SELECT
, INSERT
, UPDATE
, DELETE
, CREATE
, and DROP
. Each one performs a specific action on the database.
3. What does SELECT * do?
SELECT * retrieves all columns from a table. However, you should specify columns in production to avoid retrieving unnecessary data.
4. What is the WHERE clause used for?
The WHERE clause filters records that meet a specified condition. For instance, SELECT * FROM students WHERE age > 18;
returns adult students.
5. What is ORDER BY?
ORDER BY sorts query results in ascending (ASC
) or descending (DESC
) order based on one or more columns.
6. How do you insert data?
You use INSERT INTO
followed by table name and column values. Example: INSERT INTO users (name, age) VALUES ('Alice', 23);
7. How do you update records?
Use the UPDATE
statement with a WHERE clause. For example: UPDATE users SET age = 24 WHERE name = 'Alice';
8. How do you delete records?
Use the DELETE FROM
statement with a condition. For example: DELETE FROM users WHERE age < 18;
9. What is a primary key?
A primary key uniquely identifies each row in a table. It must be unique and NOT NULL.
10. What is a foreign key?
A foreign key creates a relationship between two tables, linking one table’s column to another table’s primary key.
Medium SQL and Database Interview Questions for Freshers
11. What is normalization?
Normalization structures tables to reduce redundancy. Developers follow rules like 1NF, 2NF, and 3NF to design efficient databases.
12. What are JOINs?
JOINs combine rows from two or more tables based on related columns. Common types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.
13. What is an INNER JOIN?
INNER JOIN returns only matching rows between tables. For example: SELECT * FROM A INNER JOIN B ON A.id = B.a_id;
14. What is a LEFT JOIN?
LEFT JOIN returns all rows from the left table and matching rows from the right table. If there’s no match, the right columns show NULL
.
15. What is GROUP BY?
GROUP BY groups rows sharing a specified column’s value. Often, you use it with aggregate functions like COUNT()
or SUM()
.
16. What is an aggregate function?
Aggregate functions perform calculations on data sets. For example, COUNT()
, SUM()
, AVG()
, MIN()
, and MAX()
.
17. What is DISTINCT?
DISTINCT removes duplicate rows in the query results. For instance: SELECT DISTINCT country FROM users;
18. What is a database index?
An index speeds up data retrieval by creating a structure that allows the database engine to find rows quickly.
19. What is a transaction?
A transaction groups a sequence of operations into an atomic unit. Developers often wrap INSERT, UPDATE, or DELETE in a transaction to maintain data integrity.
20. What does ACID stand for?
ACID represents Atomicity, Consistency, Isolation, and Durability—key database principles that ensure reliable transactions.
Advanced Interview Questions for Freshers
21. What is a subquery?
A subquery is a query within another query. For example: SELECT name FROM users WHERE id IN (SELECT user_id FROM orders);
22. What is a view?
A view is a virtual table based on the result of a query. Developers use views to simplify complex queries and enhance security.
23. What is data denormalization?
Denormalization adds redundant data deliberately to speed up read-heavy queries, although it may cause update anomalies.
24. What are stored procedures?
Stored procedures are compiled SQL code stored in the database. Developers call them to execute complex logic efficiently.
25. What is an index scan vs table scan?
An index scan uses an index structure to retrieve data faster, while a table scan reads all rows in the table, which slows down performance.
26. What are Database Transactions isolation levels?
Common isolation levels include READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE. Each level balances performance and data consistency.
27. What is a composite key?
A composite key uses two or more columns together as the primary key. Developers use it when no single column can uniquely identify a row.
28. What is referential integrity?
Referential integrity maintains consistency across related tables. In other words, foreign keys must relate to existing primary keys.
29. What is a deadlock in SQL?
A deadlock occurs when two or more transactions wait for each other to release locks. Developers often resolve them by rolling back one of the transactions.
30. How do you optimize SQL queries?
Developers optimize queries using proper indexing, avoiding SELECT *, using joins efficiently, and minimizing subqueries. Moreover, they analyze execution plans and tune queries accordingly.
Conclusion:
Finally, practicing these SQL and database interview questions for freshers will sharpen your understanding and prepare you thoroughly for real interviews. Additionally, try to work on sample databases to reinforce your learning.