Junior Database Interview Questions and Answers
1. What is a database?
A database is an organized collection of structured data stored electronically in a computer system.
It allows for easy access, management, and updating of data.
2. What is a primary key?
A primary key is a unique identifier for a record in a database table. It ensures that no two records
have the same key, and it cannot contain NULL values.
3. What is a foreign key?
A foreign key is a column or a set of columns in one table that refers to the primary key in another
table. It is used to link two tables together and enforce referential integrity.
4. What are SQL and NoSQL databases?
- SQL databases are relational databases that use Structured Query Language (SQL) for defining
and manipulating data. Examples: MySQL, PostgreSQL.
- NoSQL databases are non-relational databases designed for large-scale data storage. They are
often used for big data and real-time web applications. Examples: MongoDB, Cassandra.
5. What is normalization? Why is it important?
Normalization is the process of organizing data in a database to minimize redundancy and improve
data integrity. It involves dividing a database into tables and defining relationships between them to
eliminate duplicate data and dependencies.
6. What are the different normal forms?
- 1NF (First Normal Form): Eliminates duplicate columns and creates separate tables for related
data.
- 2NF (Second Normal Form): Ensures that all non-primary key attributes are fully dependent on the
primary key.
- 3NF (Third Normal Form): Ensures that all columns are dependent only on the primary key and not
on other non-primary key columns.
7. What is indexing? How does it improve performance?
Indexing is a technique used to improve the speed of data retrieval in a database. It creates a data
structure (an index) that allows for faster searches within a table.
8. What is ACID in database management?
ACID stands for Atomicity, Consistency, Isolation, and Durability, which are the four key properties
that ensure reliable database transactions:
- Atomicity: Ensures that all operations within a transaction are completed successfully or none at
all.
- Consistency: Ensures that the database remains in a valid state before and after the transaction.
- Isolation: Ensures that transactions do not interfere with each other.
- Durability: Ensures that the results of a transaction are permanent, even in case of system failure.
9. What is a JOIN in SQL? Name different types of JOINs.
A JOIN clause is used to combine rows from two or more tables based on a related column between
them. Common types of JOINs include:
- INNER JOIN: Returns records that have matching values in both tables.
- LEFT (OUTER) JOIN: Returns all records from the left table and matched records from the right
table.
- RIGHT (OUTER) JOIN: Returns all records from the right table and matched records from the left
table.
- FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table.
10. What is the difference between DELETE and TRUNCATE in SQL?
- DELETE removes rows from a table based on a condition and can be rolled back.
- TRUNCATE removes all rows from a table, but it cannot be rolled back in most databases. It is
faster than DELETE.
11. What are transactions in SQL, and why are they important?
A transaction in SQL is a sequence of one or more SQL operations treated as a single unit of work.
Transactions ensure that database operations are executed safely, reliably, and in compliance with
ACID properties.
12. What is a stored procedure?
A stored procedure is a set of precompiled SQL statements that can be executed as a single call. It
helps in improving performance and reusing SQL code across the database.
13. What is a trigger in SQL?
A trigger is a database object that automatically executes a specified action when certain events
occur in the database, such as an INSERT, UPDATE, or DELETE operation.
14. What is denormalization and why is it used?
Denormalization is the process of introducing redundancy into a database to improve read
performance. It is often used in systems where read operations are more frequent than write
operations, such as in data warehousing.
15. What is the difference between UNION and UNION ALL in SQL?
- UNION combines the result sets of two or more SELECT statements and removes duplicates.
- UNION ALL combines the result sets of two or more SELECT statements without removing
duplicates, thus improving performance when duplicates are not a concern.