Database questions come up in almost every fresher software interview, because nearly every application uses a database. The good news is that the questions asked are fairly predictable, and a solid grasp of the fundamentals covers most of them. This guide collects the DBMS interview questions freshers are asked most often, with clear, concise answers you can actually say out loud, organized from the basics up to the topics that separate strong candidates.
- The basics (DBMS, RDBMS, keys)
- SQL fundamentals
- Normalization and design
- Joins and relationships
- Transactions and the slightly harder topics
What is a DBMS?
A DBMS (Database Management System) is software that lets you store, organize, retrieve, and manage data efficiently, while controlling access and keeping the data consistent. Examples include MySQL, PostgreSQL, Oracle, and SQL Server.
What is the difference between DBMS and RDBMS?
An RDBMS (Relational DBMS) stores data in tables (rows and columns) and supports relationships between tables using keys. A plain DBMS may store data in other formats and may not enforce relationships. Most modern databases you will use, like MySQL, are relational.
What is a primary key?
A column (or set of columns) that uniquely identifies each row in a table. It cannot be null and cannot have duplicate values. Each table has exactly one primary key.
What is a foreign key?
A column in one table that refers to the primary key of another table, creating a link between the two. It enforces referential integrity, meaning you cannot reference a record that does not exist.
What is the difference between a primary key and a unique key?
Both prevent duplicate values. A table has only one primary key and it cannot be null; a table can have multiple unique keys and a unique column can usually hold one null value. The primary key is the main row identifier.
What is the difference between a primary key and a candidate key?
A candidate key is any column (or combination) that could uniquely identify a row. A table can have several candidate keys; the one you choose as the main identifier becomes the primary key, and the rest remain as alternate keys.
What are the types of SQL commands?
The main categories are DDL (Data Definition, like CREATE, ALTER, DROP), DML (Data Manipulation, like INSERT, UPDATE, DELETE), DQL (Data Query, SELECT), DCL (Data Control, GRANT, REVOKE), and TCL (Transaction Control, COMMIT, ROLLBACK).
What is the difference between DELETE, TRUNCATE, and DROP?
DELETE removes specific rows and can be rolled back. TRUNCATE removes all rows quickly and cannot be rolled back easily, but keeps the table structure. DROP removes the entire table including its structure.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping. HAVING filters groups after a GROUP BY. For example, WHERE filters individual sales; HAVING filters customers whose total sales exceed a value.
What is the difference between CHAR and VARCHAR?
CHAR is fixed-length and pads shorter values with spaces; VARCHAR is variable-length and stores only what is needed. Use CHAR for values of consistent length, VARCHAR for variable text.
What are aggregate functions?
Functions that operate on a set of values and return a single result, such as COUNT, SUM, AVG, MIN, and MAX. They are often used with GROUP BY to summarize data.
What is the difference between GROUP BY and ORDER BY?
GROUP BY groups rows that share a value so you can aggregate them. ORDER BY sorts the result rows. They serve different purposes and are often used together.
What is normalization?
The process of organizing data to reduce redundancy and improve consistency, by dividing data into related tables and defining relationships between them. It prevents the same data from being stored in multiple places.
Why is normalization important?
It avoids duplicate data, prevents update anomalies (where changing data in one place but not another causes inconsistency), and keeps the database clean and reliable.
What are the normal forms (1NF, 2NF, 3NF)?
1NF: each column holds atomic (single) values, no repeating groups. 2NF: 1NF plus every non-key column depends on the whole primary key. 3NF: 2NF plus no non-key column depends on another non-key column. Most practical databases aim for 3NF.
What is denormalization?
Deliberately introducing some redundancy back into a normalized database to improve read performance, for example storing a calculated total to avoid recomputing it. It trades some data duplication for speed.
What is a JOIN?
A JOIN combines rows from two or more tables based on a related column, letting you pull connected data together in one result, such as orders shown with customer names.
What are the types of joins?
INNER JOIN (only matching rows from both tables), LEFT JOIN (all rows from the left table plus matches from the right), RIGHT JOIN (all rows from the right plus matches from the left), and FULL JOIN (all rows from both, matched where possible).
What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns only rows that have a match in both tables. LEFT JOIN returns all rows from the left table, with matching data from the right where it exists and nulls where it does not. Use LEFT JOIN when you want to keep unmatched left-side rows.
What are the types of relationships in a database?
One-to-one, one-to-many, and many-to-many. One-to-many is the most common (one customer, many orders). Many-to-many (students and courses) is resolved using a junction table that links the two.
What is a transaction?
A transaction is a group of database operations treated as a single unit, they all succeed together or all fail together. For example, transferring money debits one account and credits another; both must happen or neither should.
What are ACID properties?
The four guarantees of a reliable transaction: Atomicity (all or nothing), Consistency (the database stays valid), Isolation (concurrent transactions do not interfere), and Durability (committed changes survive failures). A very common interview question.
What is an index, and why use one?
An index is a data structure that speeds up searches on a column, like an index in a book. It makes reads faster but adds a small cost to writes and uses extra storage, so you index columns you search or join on frequently.
What is the difference between a clustered and a non-clustered index?
A clustered index determines the physical order of rows in the table, so there can be only one. A non-clustered index is a separate structure pointing to the rows, and a table can have many. (Exact behavior varies by database.)
What is a view?
A view is a saved query that behaves like a virtual table. It does not store data itself but presents data from one or more tables, useful for simplifying complex queries or restricting access to certain columns.
What is the difference between SQL and NoSQL databases?
SQL databases are relational, with structured tables and a fixed schema, good for related, consistent data. NoSQL databases are non-relational (documents, key-value, and so on) with flexible schemas, good for large-scale or rapidly changing unstructured data. Each suits different needs.
How to prepare effectively
Do not try to memorize answers word for word, interviewers can tell. Instead, understand each concept well enough to explain it simply and give an example, ideally from a project you built. When you can say “a foreign key links two tables, like the customer_id in the orders table of my project,” you show both knowledge and real experience, which is exactly what interviewers want from a fresher.