How DBMS is asked in placement interviews
Interviewers usually start with a definition, then push one level deeper with why or when. Asked what an index is, a strong fresher explains the structure, when it speeds queries up and when it slows writes down. Most panels also ask you to write one or two SQL queries on paper or a shared screen, and to connect DBMS to the project on your resume.
A note on symbols
Our pages cannot display the greater-than and less-than signs or the asterisk, so a few SQL conditions below are written in words, such as salary greater than 50000 or COUNT of all rows. In the interview, write them with the normal operators.
DBMS basics: 10 questions
What is a DBMS, and why use one instead of plain files?
A DBMS is software that stores, retrieves and manages data while enforcing rules on it. Compared with plain files, it removes redundancy, keeps data consistent through constraints, lets many users work at once through concurrency control, recovers after crashes and controls access. In my college project, moving attendance from CSV files to MySQL ended duplicate student entries.
What is an RDBMS?
An RDBMS stores data in relations, which are tables of rows and columns, and links tables through keys. It uses SQL for queries and enforces integrity constraints such as primary and foreign keys. MySQL, PostgreSQL, Oracle and SQL Server are common examples.
Explain the three levels of data abstraction.
The physical level describes how data is actually stored, such as files, pages and indexes. The logical level describes what data is stored and how it relates, meaning tables, columns and constraints. The view level shows each user only the part they need, such as a student portal seeing only that student's marks.
What is data independence?
It means changing one level of the schema without breaking the level above. Physical data independence lets you add an index or move storage without changing tables or queries. Logical data independence lets you add a column without rewriting applications that do not use it. Logical independence is harder to achieve.
What are DDL, DML, DCL and TCL?
DDL defines structure: CREATE, ALTER, DROP and TRUNCATE. DML works on data: SELECT, INSERT, UPDATE and DELETE. DCL controls access: GRANT and REVOKE. TCL controls transactions: COMMIT, ROLLBACK and SAVEPOINT. Some books list SELECT separately as DQL.
What is the difference between DELETE, TRUNCATE and DROP?
DELETE removes chosen rows with a WHERE clause, logs each row and can be rolled back. TRUNCATE removes all rows quickly, cannot take a WHERE clause and often resets identity counters; whether it can be rolled back depends on the database. DROP removes the table itself, including its structure, indexes and constraints.
What is the difference between a schema and an instance?
The schema is the design of the database: the tables, columns, types and constraints. It changes rarely. The instance is the actual data stored at a particular moment, which changes with every insert or update. A schema is like a building's plan and the instance is who is inside right now.
What is a view, and what is a materialized view?
A view is a saved query that behaves like a virtual table; it stores no data and runs the query each time. It simplifies complex joins and hides columns for security. A materialized view stores the query result physically, so reads are fast, but it must be refreshed when the underlying data changes.
What is the difference between a stored procedure and a function?
Both are named blocks of SQL stored in the database. A function must return a value and can be used inside a SELECT; it generally should not change data. A stored procedure may return zero or many values, can modify data and manage transactions, and is called with CALL or EXEC.
What is a trigger? Give an example.
A trigger is code the database runs automatically before or after an insert, update or delete on a table. For example, an AFTER UPDATE trigger on an orders table can write the old and new status into an audit table. Triggers are powerful but hidden, so I use them sparingly and document them.
Keys, constraints and ER modelling: 8 questions
What is the difference between a primary key and a unique key?
Both enforce uniqueness. A table has only one primary key, and it cannot contain NULL. A table can have several unique keys, and most databases allow NULL in a unique column. For example, student_id is the primary key and email is a unique key.
Explain super key, candidate key and alternate key.
A super key is any set of columns that uniquely identifies a row. A candidate key is a minimal super key, with no column you can remove. The primary key is the candidate key you choose; the remaining candidate keys are alternate keys. In a student table, roll number and email could both be candidate keys.
What is a foreign key, and what does ON DELETE CASCADE do?
A foreign key is a column that refers to the primary key of another table, enforcing referential integrity: you cannot insert an order for a customer who does not exist. ON DELETE CASCADE means that deleting the parent row automatically deletes its child rows. Alternatives are RESTRICT and SET NULL.
What is a composite key?
A composite key is a primary key made of two or more columns, because no single column is unique. In an enrolment table, neither student_id nor course_id is unique alone, but the pair is, so the pair becomes the composite primary key.
What are entities, attributes and relationships in an ER model? What is a weak entity?
An entity is a real-world object such as Student, an attribute is a property such as name, and a relationship links entities, such as Student enrols in Course. A weak entity cannot be identified by its own attributes alone and depends on an owner, like Dependent depending on Employee.
How do you store a many-to-many relationship in tables?
Create a junction table that holds the primary keys of both sides as foreign keys. For students and courses, an enrolment table with student_id and course_id, plus attributes of the relationship such as grade, models it. The pair usually becomes the composite primary key.
What is the difference between a surrogate key and a natural key?
A natural key comes from real data, such as a PAN or an email. A surrogate key is an artificial value, such as an auto-increment number or UUID, with no business meaning. Surrogate keys stay stable when real-world values change, so I usually use them as primary keys and keep natural keys unique.
What are selection, projection and join in relational algebra?
Selection picks rows that meet a condition, like WHERE. Projection picks columns, like the SELECT list. Join combines rows from two relations on a matching condition. SQL queries are translated into these operations internally before the optimiser chooses how to run them.
Normalization: 8 questions
What is normalization, and why do we do it?
Normalization organises tables to reduce redundancy and avoid insert, update and delete anomalies. For example, if a course's faculty name is repeated in every enrolment row, changing it means updating many rows and risking inconsistency. Splitting course details into their own table stores the fact once.
What is a functional dependency?
A functional dependency X to Y means that the value of X determines the value of Y. If roll number determines student name, then two rows with the same roll number must have the same name. Normal forms are defined in terms of these dependencies.
What is first normal form?
A table is in 1NF when every column holds atomic values and there are no repeating groups. Storing phone numbers as a comma-separated list in one column breaks 1NF. The fix is a separate phone table with one row per number.
What is second normal form? Give an example.
A table is in 2NF when it is in 1NF and no non-key column depends on only part of a composite key. In enrolment with key student_id plus course_id, storing course_name breaks 2NF because it depends only on course_id. Move course_name to the course table.
What is third normal form?
A table is in 3NF when it is in 2NF and no non-key column depends on another non-key column, which is a transitive dependency. If an employee table stores dept_id and dept_name, dept_name depends on dept_id rather than the employee key, so dept_name moves to a department table.
How is BCNF different from 3NF?
BCNF is stricter: for every non-trivial functional dependency X to Y, X must be a super key. 3NF allows an exception when Y is part of some candidate key. Most 3NF tables are already in BCNF; the difference shows up with overlapping composite candidate keys.
What are lossless join and dependency preservation?
When you split a table, a lossless join means rejoining the pieces gives back exactly the original rows, with no extra ones. Dependency preservation means every original functional dependency can still be checked within single tables. Decomposition to 3NF can always keep both; BCNF sometimes cannot preserve dependencies.
When would you denormalize?
When reads dominate and joins become the bottleneck, such as a reporting dashboard or a product listing page. I might store a precomputed order total or copy a category name into a product table. The cost is extra storage and keeping copies in sync, so I do it only after measuring.
SQL query questions: 13 questions
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping and cannot use aggregate functions. HAVING filters groups after GROUP BY and can use aggregates. For example, WHERE city = 'Pune' keeps Pune rows, while HAVING SUM(amount) above a threshold keeps only departments whose total crosses it.
Write a query to find the second highest salary.
SELECT MAX(salary) FROM employee WHERE salary NOT IN (SELECT MAX(salary) FROM employee). It returns NULL if there is no second value, which is usually the desired behaviour. Another version is SELECT DISTINCT salary FROM employee ORDER BY salary DESC LIMIT 1 OFFSET 1 in MySQL or PostgreSQL.
How do you find the Nth highest salary, and how do RANK, DENSE_RANK and ROW_NUMBER differ?
Use a window function: rank salaries with DENSE_RANK() OVER (ORDER BY salary DESC) in a subquery and keep rows where the rank equals N. ROW_NUMBER gives unique numbers even for ties. RANK gives ties the same number and then skips, like 1, 1, 3. DENSE_RANK gives ties the same number without gaps, like 1, 1, 2, which is why it suits Nth highest.
How do you find duplicate emails in a users table?
SELECT email, COUNT(email) FROM users GROUP BY email HAVING COUNT(email) greater than 1. Grouping by the column puts duplicates together and HAVING keeps only groups with more than one row. To see the full rows, join this result back to the users table.
How do you delete duplicate rows but keep one copy?
Number the rows within each duplicate group with ROW_NUMBER() OVER (PARTITION BY email ORDER BY id), then delete every row whose number is not 1. In MySQL you can also delete with a self join that removes rows having the same email and a larger id. Always run it as a SELECT first.
What is the difference between UNION and UNION ALL?
Both stack the results of two queries with matching columns. UNION removes duplicate rows, which needs a sort or hash step. UNION ALL keeps every row and is faster. I use UNION ALL unless I actually need duplicates removed.
What is a correlated subquery?
A correlated subquery refers to a column of the outer query, so it runs once for each outer row. For example, finding employees who earn more than their department's average compares each row with an average computed for that row's department. It can be slow, so a join with a grouped subquery or a window function is often better.
Write a query to count employees in each department, including departments with none.
SELECT d.name, COUNT(e.id) FROM department d LEFT JOIN employee e ON e.dept_id = d.id GROUP BY d.name. The LEFT JOIN keeps departments with no employees, and COUNT(e.id) counts only matched rows, so empty departments show 0 rather than 1.
How does NULL behave in comparisons?
NULL means unknown, so any comparison with NULL, even NULL = NULL, gives unknown, which WHERE treats as false. Use IS NULL and IS NOT NULL instead. Aggregates such as SUM and AVG ignore NULLs, and COALESCE(bonus, 0) replaces NULL with a default.
In what order does SQL logically process a SELECT query?
FROM and JOIN first, then WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY and finally LIMIT or OFFSET. That is why you cannot use a SELECT alias in WHERE in most databases, but you can use it in ORDER BY.
What is the difference between CHAR and VARCHAR?
CHAR is fixed length: CHAR(10) always uses space for 10 characters and pads shorter values. VARCHAR is variable length and stores only what is needed plus a small length marker. CHAR suits fixed codes such as a two-letter state code; VARCHAR suits names and emails.
When would you use EXISTS instead of IN?
EXISTS checks whether the subquery returns any row and can stop at the first match, which helps with large correlated subqueries. IN compares a value against a list. Another reason is NULLs: NOT IN returns no rows if the subquery contains a NULL, while NOT EXISTS behaves as expected.
What is the difference between COUNT of a column and COUNT of all rows?
COUNT(column) counts only rows where that column is not NULL. COUNT of all rows, written with an asterisk, counts every row including those with NULLs. COUNT(DISTINCT column) counts unique non-NULL values. Mixing these up gives wrong totals in reports.
Joins, indexes and query performance: 8 questions
Explain the types of joins.
INNER JOIN returns only matching rows. LEFT JOIN returns all rows from the left table plus matches, with NULLs where there is no match. RIGHT JOIN is the mirror. FULL OUTER JOIN returns all rows from both sides. CROSS JOIN returns every combination. A self join joins a table to itself.
When would you use a self join?
When rows in one table refer to other rows in the same table. An employee table with a manager_id column is the classic case: joining employee e to employee m on e.manager_id = m.id lists each employee with their manager's name.
What is an index, and how does a B+ tree index help?
An index is a separate structure that lets the database find rows without scanning the whole table. Most relational databases use B+ trees: balanced trees whose leaves hold keys in sorted order and are linked, so both exact lookups and range scans take a few page reads instead of thousands.
What is the difference between a clustered and a non-clustered index?
A clustered index decides the physical order of rows, so a table can have only one; in MySQL InnoDB the primary key is the clustered index. A non-clustered index is a separate structure that stores the key and a pointer or primary key to the row, and a table can have many.
When can an index make things worse?
Every insert, update and delete must also update each index, so too many indexes slow writes and use storage. Indexes on low-variety columns such as a yes or no flag rarely help. A function on an indexed column, such as LOWER(email), can also stop the plain index from being used.
What is a composite index, and what is the leftmost prefix rule?
A composite index covers several columns in a fixed order, such as (city, age). It helps queries that filter on city, or on city and age, but generally not on age alone, because the index is sorted by city first. So I order columns by how queries filter.
How would you speed up a slow query?
First I read the execution plan with EXPLAIN to see whether it scans the full table. Then I add or adjust an index on the filter and join columns, select only needed columns, avoid functions on indexed columns, and check for N plus 1 queries from the application. Finally I measure again.
What is a covering index?
A covering index contains every column a query needs, so the database answers from the index alone without visiting the table. For a query that selects email by user_id, an index on (user_id, email) covers it. It speeds hot read paths at the cost of a larger index.
Transactions, concurrency and recovery: 10 questions
What is a transaction, and what does ACID mean?
A transaction is a group of operations treated as one unit, such as debiting one account and crediting another. Atomicity means all or nothing. Consistency means constraints hold before and after. Isolation means concurrent transactions do not see each other's half-done work. Durability means committed data survives a crash.
How does a database guarantee atomicity and durability?
Through logging. Before changing data pages, the database writes the change to a log, which is called write-ahead logging. On a crash, it redoes committed changes from the log and undoes uncommitted ones. Commit returns only after the log record is safely on disk.
What are dirty reads, non-repeatable reads and phantom reads?
A dirty read sees another transaction's uncommitted change. A non-repeatable read gets a different value when it reads the same row twice because someone committed an update in between. A phantom read gets a different set of rows for the same query because someone inserted or deleted matching rows.
Explain the SQL isolation levels.
Read Uncommitted allows dirty reads. Read Committed prevents them but allows non-repeatable reads. Repeatable Read keeps rows you read stable, though the standard still allows phantoms. Serializable makes transactions behave as if they ran one after another. PostgreSQL defaults to Read Committed and MySQL InnoDB to Repeatable Read.
What are shared and exclusive locks?
A shared lock lets several transactions read the same data but blocks writers. An exclusive lock is taken for writing and blocks both readers using locks and other writers. Two shared locks are compatible; an exclusive lock is compatible with nothing.
What is two-phase locking?
In two-phase locking, a transaction first acquires all the locks it needs, the growing phase, and then releases them, the shrinking phase, never acquiring a new lock after releasing one. This guarantees conflict-serializable schedules. Strict 2PL holds write locks until commit to avoid cascading rollbacks.
What is a deadlock in a database, and how is it handled?
A deadlock happens when transaction A holds a lock B needs while B holds a lock A needs. Databases detect it with a wait-for graph and roll back one transaction as the victim. In application code, I reduce deadlocks by accessing tables in a consistent order and keeping transactions short.
What is the difference between optimistic and pessimistic concurrency control?
Pessimistic control locks data before using it, which is safe when conflicts are frequent. Optimistic control does not lock; it checks at write time whether the data changed, often with a version column, and retries if it did. Optimistic suits read-heavy apps such as profile edits.
What is conflict serializability?
A schedule is conflict serializable if swapping non-conflicting operations can turn it into some serial order. Two operations conflict when they belong to different transactions, touch the same item, and at least one is a write. You test it by drawing a precedence graph: no cycle means serializable.
What are COMMIT, ROLLBACK, SAVEPOINT and checkpoints?
COMMIT makes a transaction's changes permanent and ROLLBACK undoes them. SAVEPOINT marks a point inside a transaction so you can roll back part of it. A checkpoint is a recovery mechanism: the database flushes dirty pages and records a point in the log, so crash recovery starts from there instead of the log's beginning.
NoSQL, scaling and design: 6 questions
When would you choose NoSQL over SQL?
I choose SQL when data is relational and I need joins, strong constraints and transactions, such as payments or college records. NoSQL suits flexible or rapidly changing structures, very high write volume, or simple key-based access, such as session stores, event logs or product catalogues with varied attributes.
What is the CAP theorem?
For a distributed data store, CAP says that when a network partition happens, you must choose between consistency, where every read sees the latest write, and availability, where every request gets a response. Since partitions cannot be ruled out, real systems choose a trade-off for partition time.
What is the difference between replication and sharding?
Replication copies the same data to several servers, which helps read scaling and availability. Sharding splits data across servers by a key, such as user id ranges or a hash, which helps write scaling and storage. Large systems often use both: each shard is replicated.
Design a simple schema for a college library.
Tables: member with member_id, name and type; book with book_id, title, author and ISBN; copy with copy_id and book_id, because one title has many copies; and loan with loan_id, copy_id, member_id, issue_date, due_date and return_date. Foreign keys link loan to copy and member, and an index on due_date speeds overdue reports.
What is an ORM, and what is the N plus 1 query problem?
An ORM maps tables to objects in code, such as Hibernate or Sequelize. The N plus 1 problem happens when code loads a list of N records and then lazily runs one more query per record for related data. The fix is eager loading or a join, which gets everything in one or two queries.
How did you use a database in your project?
In my final-year placement-tracker project, I used PostgreSQL with tables for students, companies, drives and applications. Applications linked students and drives in a many-to-many relationship. I added a unique constraint on student and drive so no one applied twice, and an index on drive_id that took the shortlist query from seconds to milliseconds.
Replace the details with your own project; the interviewer checks that you made real design choices and can explain them.
What the interviewer, and the AI panel, listens for
- A definition in one sentence, followed by a concrete example from a table you can describe.
- Trade-offs: indexes speed reads and slow writes; normalization reduces redundancy and adds joins.
- Correct SQL with edge cases handled: NULLs, ties and empty groups.
- Honesty: if you do not know a database-specific detail, say how you would check it.
Test your recall first on the free DBMS concepts test and the drawn placement CS fundamentals test. Then answer these questions aloud with the ExamPilot AI interviewer, which follows up the way a real panel does. For lab-style definitions, see the DBMS viva questions guide.
Two-week DBMS preparation plan
- 1
Days 1 to 3: basics, keys and ER
Learn the definitions above and draw the ER diagram of your own project, with keys marked.
- 2
Days 4 to 6: normalization
Take two messy tables from real life, such as a mess bill or a timetable, and normalise each to 3NF aloud.
- 3
Days 7 to 10: SQL by hand
Write 30 queries on a sample employee and department schema: joins, GROUP BY, HAVING, subqueries and window functions. Run them on a free local PostgreSQL or MySQL install.
- 4
Days 11 to 14: transactions and mock rounds
Revise ACID, isolation and locking with your own examples, then do two spoken mock rounds and fix the answers that came out vague.
Frequently asked questions
- What are the most asked DBMS interview questions for freshers?
- Primary vs unique key, normalization up to 3NF or BCNF, ACID properties, types of joins, DELETE vs TRUNCATE vs DROP, indexes, and SQL queries such as the second highest salary and finding duplicates. Expect at least one question that links DBMS to your own project.
- How is a DBMS interview different from a DBMS viva?
- A viva tests definitions from your syllabus and lab programs. An interview goes further into why and when: trade-offs of indexes, choosing isolation levels, writing correct queries with edge cases and designing a schema. Use the viva guide for quick definitions and this page for depth.
- Which SQL database should I practise on?
- Either MySQL or PostgreSQL is fine for interviews, since both follow standard SQL for the queries freshers are asked. Install one locally, create a small employee and department schema, and run every query in this guide to see the output yourself.
- Do I need to know NoSQL for fresher interviews?
- Basic awareness is enough for most fresher roles: when to choose NoSQL over SQL, the idea of the CAP theorem, and the difference between replication and sharding. Backend and data roles may ask more, especially if MongoDB or Redis appears on your resume.
- Where can I practise DBMS questions for free?
- ExamPilot's DBMS concepts test and the placement CS fundamentals test are free, with explanations after each attempt. To practise answering aloud, run a fresher technical mock interview with the AI interviewer.
Practise out loud
Practise a DBMS technical round aloud
The AI interviewer asks DBMS and SQL questions in a fresher technical round, follows up on your answers and tells you where your explanation was vague.
Placements · Fresher — IT services
