Database interview questions check how well you know the way data is stored, linked and kept safe. Most rounds come back to the same topics: keys, normal forms, joins, indexes and transactions. So if you can explain those five in plain words, with a small example for each, you can handle most fresher and mid-level rounds.
The 100 questions run from the basics to NoSQL, backups and design. Each one has a short answer you can say out loud in under a minute. You will also find a table on isolation levels and a look at pay for database jobs. Last, a short table maps the topics that matter most for each role.
Database Interview Questions on Basics and Core Terms
These first questions come up in almost every round, even for senior roles. Interviewers use them to see if you can explain simple ideas without jargon.
1. What is a database?
A database is an organized set of data stored so a program can find, add and change it fast. For example, a bank keeps accounts, customers and payments in a database. You read and write that data through software, such as an app or a SQL client.
2. What is a DBMS?
A DBMS, or database management system, is the software that runs a database. It stores the data and answers queries. It also checks rules and controls who can see what. MySQL, PostgreSQL, Oracle, SQL Server and MongoDB are all DBMS products.
3. How is a DBMS better than a plain file system?
A file system just saves files, so each program has to handle its own rules. A DBMS, by contrast, gives you one shared copy of the data with fast search and access control. It also handles backups and safe updates when many users write at once. It also cuts down on the same data being stored in many places.
4. What is an RDBMS?
An RDBMS is a relational DBMS. So it stores data in tables made of rows and columns and links tables through keys. You query it with SQL. PostgreSQL, MySQL, Oracle Database and Microsoft SQL Server are common examples.
5. What are tables, rows and columns?
A table holds data about one kind of thing, such as customers. Each row is one record, like one customer, while each column is one detail, like the email address. In formal terms, a row is a tuple and a column is an attribute.
6. What is a schema?
A schema is the design of a database. It names the tables, the columns, their data types and the rules between them. In PostgreSQL, a schema is also a named folder inside a database that groups tables, so sales.orders and hr.orders can both exist.
7. What is the three-level database architecture?
The ANSI-SPARC model splits a database into three levels. First, the external level is what each user or app sees. The conceptual level is the full logical design of all the data. The internal level is how the data sits on disk. This split lets you change one level without breaking the others.
8. What is data independence?
Data independence means you can change one level of the design without rewriting apps. Physical independence lets you move files or add an index without changing the logical design. Logical independence lets you add a column or table without breaking the views that apps use. Logical independence is harder to get in practice.
9. What are DDL, DML, DCL and TCL?
These are the four groups of SQL commands. First, DDL defines structure, with CREATE, ALTER and DROP. DML works on data, with SELECT, INSERT, UPDATE and DELETE. DCL handles access, with GRANT and REVOKE. TCL controls transactions, with COMMIT, ROLLBACK and SAVEPOINT.
10. What is a data dictionary?
A data dictionary, also called the system catalog, is a set of tables the DBMS keeps about your database. It records table names, columns, types, indexes, users and rights. For example, you can query information_schema.columns in MySQL or PostgreSQL to see every column in a table.
11. What is the difference between a schema and an instance?
The schema is the design, and it rarely changes. The instance is the data stored at one moment, and it changes with every insert or delete. So a schema is like the blank form, while the instance is the stack of filled forms today.
12. What is a data model?
A data model is a way to describe how data is shaped and linked. The relational model uses tables. Older systems used the hierarchical model, a tree, and the network model, a graph of records. Today you also see document, key-value and graph models in NoSQL systems.
13. What is an ER diagram?
An ER diagram, or entity-relationship diagram, is a drawing of the data before you build tables. Boxes show entities like Student and Course. Lines show how they relate, such as a student enrolls in many courses. Designers use it to agree on the model with the team first.
14. What is a weak entity?
A weak entity cannot be named by its own columns alone. It needs the key of a parent entity. For example, an order line only makes sense with its order, so its key is the order number plus a line number. In ER diagrams, a weak entity has a double box.
15. What is cardinality in a relationship?
Cardinality tells you how many rows on one side link to rows on the other. For example, one-to-one means one person has one passport. One-to-many means one customer has many orders. Many-to-many means students and courses, which you model with a third table, often called a junction table.
Keys, Constraints and Integrity
Keys come up in nearly every database interview, so expect follow-up questions here. Have a small example ready, such as a students table.
16. What is a primary key?
A primary key is the column, or set of columns, that names each row uniquely. It cannot be NULL and cannot repeat. A table has only one primary key. For example, student_id in a students table is a common primary key.
17. What is a candidate key?
A candidate key is any minimal set of columns that could serve as the primary key. For example, a students table might have student_id, email and roll_number, all unique. Each is a candidate key. You pick one as the primary key.
18. What is a super key?
A super key is any set of columns that uniquely names a row, even if it has extra columns. So student_id alone is a super key, and student_id plus name is also one. A candidate key is a super key with nothing extra in it.
19. What is an alternate key?
An alternate key is a candidate key you did not choose as the primary key. If student_id is the primary key, then email and roll_number become alternate keys. You usually put a UNIQUE rule on them.
20. What is a foreign key?
A foreign key is a column that points to the primary key of another table. For example, orders.customer_id points to customers.customer_id. The database then blocks an order for a customer who does not exist. That rule is called referential integrity.
21. What is a composite key?
A composite key is a key made of two or more columns. In an enrollments table, neither student_id nor course_id is unique alone. Together, though, they name one enrollment, so the pair forms the composite primary key.
22. What is the difference between a natural key and a surrogate key?
A natural key comes from real data, like a passport number or an email. A surrogate key is a made-up number, often an auto-increment ID or a UUID. Surrogate keys never change, so most teams use them as primary keys and keep natural keys unique on the side.
23. How is a unique key different from a primary key?
Both stop repeats. However, a table can have many unique keys but only one primary key. A primary key never allows NULL. A unique key allows NULL in most systems, and PostgreSQL and MySQL let you store more than one NULL in a unique column.
24. What constraints can you put on a table?
The common ones are NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK and DEFAULT. For example, CHECK (salary > 0) blocks a negative salary. Constraints keep bad data out at the source, so every app that writes to the table follows the same rules.
25. What do ON DELETE CASCADE and ON DELETE SET NULL do?
These rules say what happens to child rows when a parent row is deleted. CASCADE deletes the child rows too. SET NULL keeps them but blanks out the foreign key. RESTRICT or NO ACTION blocks the delete while children exist. Pick CASCADE with care, since one delete can wipe many rows.
26. What is NULL, and why is it tricky?
NULL means a value is unknown or missing. It is not zero and not an empty string. Because of that, any compare with NULL returns unknown, so WHERE phone = NULL finds nothing. You need IS NULL or IS NOT NULL instead. SQL uses three-valued logic: true, false and unknown.
27. What is entity integrity?
Entity integrity is the rule that every row must have a primary key value, and that value cannot be NULL. Without it, you could not tell two rows apart. Referential integrity, by contrast, is the rule for foreign keys.
Normalization and Normal Forms
Normal forms trip up many freshers, so learn them with one running example. Interviewers often hand you a messy table and ask you to split it.
28. What is normalization?
Normalization is the process of splitting tables to remove repeated data and odd update problems. You break one wide table into smaller linked tables. As a result, each fact lives in one place, so a change happens once.
29. What are insert, update and delete anomalies?
These are bugs caused by a badly designed table. An insert anomaly means you cannot add a course until a student takes it. An update anomaly means a teacher’s phone sits in 50 rows, and you miss one. A delete anomaly means removing the last student also removes the only record of the course.
30. What is a functional dependency?
A functional dependency, written A → B, means the value of A decides the value of B. For example, student_id → student_name, since one ID always maps to one name. Normal forms are defined in terms of these rules.
31. What is first normal form (1NF)?
A table is in 1NF when every cell holds one value and there are no repeating groups. So a phones column with “98100, 98200” breaks 1NF. To fix it, you move phone numbers to their own table, one number per row.
32. What is second normal form (2NF)?
A table is in 2NF when it is in 1NF and no non-key column depends on only part of a composite key. In enrollments(student_id, course_id, course_name), the course name depends only on course_id. So you move course_name to a courses table.
33. What is third normal form (3NF)?
A table is in 3NF when it is in 2NF and no non-key column depends on another non-key column. In employees(emp_id, dept_id, dept_name), the department name depends on dept_id, not on the employee. That is a transitive dependency, so dept_name moves to a departments table.
34. What is BCNF?
Boyce-Codd normal form is a stricter 3NF. Every determinant, meaning anything on the left of a dependency, must be a candidate key. A table can be in 3NF and still break BCNF when it has overlapping candidate keys. Most business tables that reach 3NF are also in BCNF.
35. What is fourth normal form (4NF)?
4NF removes multi-valued dependencies. Say one table stores a teacher’s subjects and the teacher’s hobbies. Those two lists have nothing to do with each other, yet the table must store every pair. So you split it into teacher_subjects and teacher_hobbies.
36. What is fifth normal form (5NF)?
5NF, also called project-join normal form, deals with join dependencies. A table is in 5NF when you cannot split it further without losing data on rejoin. It shows up with three-way links, such as supplier, part and project. In practice, few interviews go past 4NF.
37. What is denormalization, and when do you use it?
Denormalization means adding back some repeated data on purpose to make reads faster. Reports and dashboards often do this, since joining ten tables on every page view is slow. The cost is extra storage and more care on updates, so you only denormalize after you measure a real slowdown.
38. What is a lossless join decomposition?
A split is lossless when joining the smaller tables gives back the exact first table, with no fake rows. The rule of thumb: the shared column of the two parts must be a key in at least one of them. A lossy split, by contrast, creates rows that never existed.
39. What is dependency preservation?
A split keeps dependencies when you can still check every functional dependency inside a single smaller table. If a rule spans two tables, the database must join them to check it, which is slow. Going to BCNF can sometimes lose this, which is why many designs stop at 3NF.
40. How do you find candidate keys using attribute closure?
Take a set of columns and add every column it decides, using the dependencies, until nothing new appears. That result is the closure. If the closure has every column of the table, the set is a super key. If no smaller subset does the same, it is a candidate key. For R(A, B, C, D) with A → B and B → C, the closure of AD is ABCD, so AD is a candidate key.
Read also: 100 Machine Learning Interview Questions
SQL Objects and Relational Algebra
This group connects theory to the SQL you write every day. So expect at least one question on views or joins.
41. What are the basic operations of relational algebra?
The core ones are select (σ), which filters rows, and project (π), which picks columns. Then come union, set difference, Cartesian product and rename. Join, intersection and division are built from those. SQL queries are turned into these operations inside the database.
42. What is the difference between relational algebra and relational calculus?
Relational algebra is procedural. You say the steps, such as filter, then join, then project. Relational calculus, on the other hand, is declarative. You describe what the result should look like and leave the steps to the system. SQL is closer to calculus, while the query plan is closer to algebra.
43. What types of joins are there?
An inner join returns only matching rows. By contrast, a left join returns all rows from the left table plus matches. A right join does the same for the right table. A full outer join returns all rows from both. A cross join returns every pair, and a self join joins a table to itself.
44. How is a natural join different from an equi join?
An equi join matches rows with an equals sign on columns you name. A natural join matches on every column with the same name in both tables, and shows that column once. Natural joins are risky, because adding a column like updated_at to both tables silently changes the result.
45. What is a view?
A view is a saved query that acts like a table. It stores no data of its own. For example, active_customers could be a view over customers WHERE status = 'active'. Views hide complex joins and limit which columns a user can see.
46. What is a materialized view?
A materialized view stores the result of its query on disk. So reads are fast, but the data can go stale. You refresh it on a schedule or on demand, as with REFRESH MATERIALIZED VIEW in PostgreSQL. Teams use them for heavy reports.
47. What is the difference between a subquery and a correlated subquery?
A plain subquery runs once and hands its result to the outer query. A correlated subquery uses a value from the outer row, so in theory it runs once per row. For example, finding employees paid above their own department’s average needs a correlated subquery. Modern optimizers often rewrite it as a join.
48. What is the difference between a stored procedure and a function?
A stored procedure is saved code you call to do work, and it can run inserts, updates and transaction control. A function returns a value and can be used inside a SELECT. In SQL Server, for example, functions cannot change table data. Rules vary by database, so mention which one you use.
49. What is a trigger?
A trigger is code that runs on its own when an event hits a table, such as an insert, update or delete. For example, a trigger can write an audit row each time a salary changes. Triggers are handy, but too many of them make bugs hard to trace.
50. What is a cursor?
A cursor lets you walk through a query result one row at a time inside a procedure. It is useful when each row needs its own logic. However, cursors are slow compared with set-based SQL, so use them only when a single query cannot do the job.
Transactions, ACID and Concurrency
This is where interviews for backend and DBA roles get deep. So learn the four isolation levels and what each one allows.
51. What is a transaction?
A transaction is a group of database steps that must succeed or fail as one unit. For example, moving ₹5,000 from one account to another is the classic case. The debit and the credit both happen, or neither does.
52. What does ACID stand for?
ACID stands for atomicity, consistency, isolation and durability. Atomicity means all or nothing. Consistency means every rule holds before and after. Isolation means running transactions do not see each other’s half-done work. Durability means a committed change survives a crash.
53. What are the stages of a transaction?
A transaction starts as active while it runs its steps. After the last step, it is partially committed. If all goes well, it becomes committed. If something fails, it moves to failed and then aborted, and the database rolls back its changes. After that, the app can retry or give up.
54. What are COMMIT, ROLLBACK and SAVEPOINT?
COMMIT makes the changes of a transaction permanent. ROLLBACK undoes them. SAVEPOINT marks a point inside a transaction, so you can roll back to that point without losing earlier work. For example, a long import can save a point after each batch.
55. What problems happen when transactions run at the same time?
A dirty read means reading data another transaction has not committed. Next, a non-repeatable read means the same row gives a new value on a second read. A phantom read means a repeat query returns new rows. A lost update means two writers overwrite each other. Isolation levels exist to block these.
56. What are the four isolation levels?
The SQL standard defines Read Uncommitted, Read Committed, Repeatable Read and Serializable, from weakest to tightest. Each level blocks more of the problems in the last answer, at the cost of more waiting or more retries. Defaults differ: PostgreSQL uses Read Committed, while MySQL’s InnoDB engine uses Repeatable Read.
| Level | Reads data not yet saved | Same row reads back new value | New rows show up on rerun |
|---|---|---|---|
| Read Uncommitted | Can (but not in PostgreSQL) | Can | Can |
| Read Committed | No | Can | Can |
| Repeatable Read | No | No | Can (but not in PostgreSQL) |
| Serializable | No | No | No |
In PostgreSQL, Read Uncommitted acts the same as Read Committed. Also, its Repeatable Read blocks phantom reads, even though the standard allows them at that level.

57. What is serializability?
A schedule of transactions is serializable when its result matches some order of running them one after another. Conflict serializability checks this with a precedence graph: if the graph has no cycle, the schedule is safe. View serializability is a wider test, but it is too costly to check in real systems.
58. What is the difference between a shared lock and an exclusive lock?
A shared lock lets many transactions read a row at once. An exclusive lock lets one transaction write, and blocks others from reading or writing that row with locks. So two readers never block each other, but a writer blocks everyone else.
59. What is two-phase locking?
Two-phase locking (2PL) is a rule with two phases. In the first, a transaction takes the locks it needs. In the second, it releases them and never takes a new lock again. This gives serializable results. Strict 2PL holds write locks until commit, which also prevents other transactions from reading dirty data.
60. What is a deadlock, and how is it handled?
A deadlock happens when two transactions each hold a lock the other needs, so both wait forever. Most databases detect this with a wait-for graph, then roll back one transaction, the victim. To prevent deadlocks, take locks in the same order in all code and keep transactions short.
61. What is the difference between optimistic and pessimistic locking?
Pessimistic locking locks a row before changing it, so others wait. Optimistic locking does not lock. Instead, it checks at save time that nobody else changed the row, often with a version column. Optimistic locking works well when conflicts are rare, such as editing a user profile.
62. What is MVCC?
MVCC, or multi-version concurrency control, keeps old versions of rows so readers see a stable snapshot while writers make changes. As a result, readers do not block writers and writers do not block readers. PostgreSQL, MySQL’s InnoDB and Oracle all use forms of MVCC. Old versions are cleaned up later, as with VACUUM in PostgreSQL.
63. What is the timestamp ordering protocol?
Each transaction gets a timestamp when it starts. The database then makes sure conflicting reads and writes happen in timestamp order. If a transaction tries to read or write data that a younger transaction already wrote, it is rolled back and restarted. No locks are needed, so there are no deadlocks.
64. What is write-ahead logging?
Write-ahead logging (WAL) means every change is written to a log on disk before the data pages change. After a crash, the database replays the log to redo committed work and undo the rest. That is how databases deliver durability without writing every page right away.
65. What is a checkpoint?
A checkpoint is a moment when the database flushes changed pages from memory to disk. It then writes a checkpoint record to the log. On restart, recovery only needs to replay the log from the last checkpoint onward. So checkpoints keep crash recovery short.
66. How does crash recovery work?
Recovery uses the log in two passes. First, redo replays every logged change after the last checkpoint, so committed work is back. Then undo reverses changes from transactions that never committed. The ARIES method, used in IBM DB2 and SQL Server, adds an analysis pass before these two.
Indexes, Storage and Query Plans
Performance questions show if you have run real systems. So tie each answer to a slow query you have fixed, if you have one.
67. What is an index?
An index is a separate structure that lets the database find rows without reading the whole table. It works like the index at the back of a book. For example, an index on email lets a login query jump straight to one user out of ten million.
68. Why do databases use B-trees and B+ trees for indexes?
A B+ tree stays balanced, so every lookup takes the same small number of steps, even on huge tables. Each node holds many keys, which matches disk pages and keeps the tree short. Leaf nodes link to each other, so range scans like BETWEEN and ORDER BY are fast. In PostgreSQL, B-tree is the default index type.
69. What is the difference between a clustered and a non-clustered index?
A clustered index sets the order of the table’s rows on disk, so a table can have only one. A non-clustered index is a separate structure that points back to the rows. In SQL Server, the primary key becomes the clustered index by default. In MySQL’s InnoDB, the table is always clustered on its primary key.
70. What other index types exist?
Hash indexes handle only equality checks. Bitmap indexes, found in Oracle, work best on columns with few values in reporting systems. PostgreSQL also offers GiST, SP-GiST, GIN and BRIN. GIN helps with full-text search and JSON, while BRIN keeps tiny summaries for huge tables sorted by time.
71. What is a composite index, and what is the leftmost prefix rule?
A composite index covers more than one column, such as (last_name, first_name). The database can use it for a search on last_name alone, or on both columns. However, it usually cannot use it for first_name alone, because the index is sorted by the first column first.
72. What is a covering index?
A covering index holds every column a query needs, so the database answers from the index alone and never touches the table. For example, an index on (customer_id, order_date, amount) covers a query that sums amount by date for one customer. SQL Server and PostgreSQL support INCLUDE columns for this.
73. When can an index hurt performance?
Every insert, update and delete must also update each index, so too many indexes slow writes. Indexes also take disk and memory. On a tiny table, or a column with only a few values like status, a full scan is often faster. So add indexes for real queries, not for every column.
74. What is selectivity?
Selectivity is the share of rows a filter returns. A filter on email returns one row, so it is highly selective and a great index choice. A filter on country = 'India' in an Indian app returns most rows, so an index there helps little. The optimizer uses stats on selectivity to pick a plan.
75. What is a query optimizer?
The query optimizer is the part of the DBMS that picks how to run a query. It weighs plans, such as which index to use and which join order. Then it picks the one with the lowest estimated cost. You can see its choice with EXPLAIN in MySQL and PostgreSQL.
76. What is the difference between a full table scan and an index scan?
A full table scan reads every row in the table. An index scan walks the index to find matching rows and then fetches them. For a query that returns most of the table, a full scan can be faster, because it reads pages in order. So a full scan in a plan is not always a bug.
77. What is table partitioning?
Partitioning splits one large table into smaller pieces that still look like one table. Range partitioning splits by date, list partitioning splits by a set of values like region, and hash partitioning spreads rows evenly. Queries that filter on the partition column skip the pieces they do not need.
78. What is sharding?
Sharding splits data across separate database servers, with each server holding part of the rows. For example, users A to M on one shard and N to Z on another. It lets you grow past one machine. The cost is harder joins across shards, harder transactions and more work when you rebalance.
79. How does a database store data on disk?
Data lives in fixed-size pages or blocks, such as 8 KB pages in PostgreSQL and 16 KB pages by default in InnoDB. Each page holds many rows. The database reads whole pages into a memory buffer pool, so a good cache hit rate means far fewer disk reads.
80. What is a heap table?
A heap table stores rows in no set order. New rows go into any page with free space. PostgreSQL tables are heaps, and indexes point to row locations. By contrast, a clustered table keeps rows sorted by its key.
NoSQL, Scaling and Data Warehouses
Even SQL-heavy roles ask a few of these now, so keep answers practical and name a real product for each type.
81. What is NoSQL, and what are its main types?
NoSQL databases store data in models other than relational tables. For example, key-value stores like Redis map a key to a value. Document stores like MongoDB keep JSON-like records. Wide-column stores like Apache Cassandra group data by column families. Graph databases like Neo4j store nodes and edges.
82. When would you pick NoSQL over SQL?
Pick NoSQL when the data shape changes often or the data is a graph. It also helps when you must spread huge write loads across many servers. Pick SQL when you need joins, strict rules and multi-row transactions, as in billing or banking. Many systems use both, such as PostgreSQL for orders and Redis for sessions.
83. What is the CAP theorem?
Under the CAP theorem, a distributed system can promise only two of three things during a network split: consistency, availability and partition tolerance. Since network splits will happen, the real choice is between consistency and availability while the split lasts. So a CP system refuses some requests, while an AP system may return old data.
84. What is the difference between ACID and BASE?
ACID favors correct data in every transaction. BASE stands for basically available, soft state and eventually consistent. It favors staying up and fast, and accepts that replicas may disagree for a short time. Banks lean on ACID, while social media feeds often accept BASE.
85. What is eventual consistency?
Eventual consistency means that if no new writes arrive, all copies of the data will end up the same. In the meantime, a read from one replica may show older data. For example, a like count may differ for a few seconds between two users.
86. What is database replication?
Replication copies data from one server to others. In primary-replica setups, one server takes writes and replicas serve reads. Multi-primary setups take writes on several nodes but must handle conflicts. Synchronous replication waits for replicas before confirming, while asynchronous replication does not, so it is faster but can lose recent writes.
87. What is replication lag, and why does it matter?
Replication lag is the delay between a write on the primary and its arrival on a replica. Say a user updates a profile, and the next screen loads from a lagging replica. In that case, they see old data. Common fixes are reading your own writes from the primary, or waiting for the replica to catch up.
88. What is consistent hashing?
Consistent hashing places servers and keys on a ring. Each key goes to the next server around the ring. When you add or remove a server, only the keys near it move. That is why Apache Cassandra and Amazon’s Dynamo design use it to spread data.
89. What is the difference between OLTP and OLAP?
OLTP systems handle many small, fast transactions, such as placing orders or booking seats. OLAP systems, by contrast, run large read-heavy queries for reports, such as sales by region for five years. OLTP tables are normalized. OLAP data is often in column stores and star schemas.
90. What is the difference between a data warehouse and a data lake?
A data warehouse stores cleaned, structured data ready for reports, such as in Snowflake or Google BigQuery. A data lake, on the other hand, stores raw data of any type, often as files in cheap storage like Amazon S3. Many teams now use a lakehouse, which adds warehouse features on top of lake files.
91. What are star and snowflake schemas?
A star schema has one central fact table, such as sales, linked to dimension tables like date, product and store. A snowflake schema, by contrast, splits those dimensions further into sub-tables. Star schemas mean fewer joins and faster reports. Snowflake schemas save space and reduce repeated data.
92. What is the difference between ETL and ELT?
ETL means extract, transform, then load. Data is cleaned before it reaches the warehouse. ELT means extract, load, then transform inside the warehouse. ELT has become common because cloud warehouses can run heavy transforms cheaply, often with a tool like dbt.
Backups, Security and Design Questions
The last group mixes admin tasks with open design questions. So for the design ones, think out loud and state your trade-offs.
93. What are full, incremental and differential backups?
A full backup copies the whole database. An incremental backup copies only what changed since the last backup of any kind. A differential backup copies what changed since the last full backup. Point-in-time recovery adds the transaction log, so you can restore to a chosen minute. Our data backup and recovery checklist walks through a full plan.
94. What are RPO and RTO?
RPO, the recovery point objective, is how much data you can afford to lose, measured in time. RTO, the recovery time objective, is how long you can afford to be down. For example, an RPO of 5 minutes and an RTO of 1 hour shape how often you back up and how fast you must restore.
95. What is SQL injection, and how do you stop it?
SQL injection happens when user input is pasted into a query string, so an attacker can change the query. For instance, typing ' OR '1'='1 into a login box might log them in. The fix is to use parameterized queries or prepared statements, never string building. Least-privilege database users limit the damage if a hole is found.
96. How do you control who can access data?
You create roles, give each role only the rights it needs with GRANT, and take rights away with REVOKE. Users then get roles. For example, a reporting role gets SELECT on a few views and nothing else. Some databases also offer row-level security, which filters rows per user.
97. What is connection pooling?
Opening a database connection is slow, so a pool keeps a set of open connections that the app reuses. Tools like PgBouncer for PostgreSQL or HikariCP in Java do this. Without pooling, a traffic spike can open thousands of connections and crash the server.
98. How does a cache like Redis work with a database?
The app first checks the cache. If the data is there, it skips the database. If not, it reads the database and saves the result in the cache with an expiry time. The hard part is invalidation: when the data changes, you must update or delete the cached copy, or users see stale data.
99. How would you design the database for an online store?
Begin with the main entities: customers, products, orders, order items, payments and addresses. Orders link to customers, and order items link orders to products with quantity and price at the time of sale. Then add indexes for common lookups, such as orders by customer. Finally, explain what you would denormalize for reports and what you would cache.
100. How do you troubleshoot a slow query?
First, get the real plan with EXPLAIN ANALYZE in PostgreSQL, or EXPLAIN in MySQL. Look for full scans on big tables, bad row estimates and costly sorts. Then check for missing indexes, functions on indexed columns, old table stats and lock waits. Fix one thing at a time and measure again.
Which Database Topics to Study First for Your Role
Not every role needs all 100 answers at the same depth. So the table maps where to spend your time, and what you can skim.
| Your role | Learn these well | Fine to skim |
|---|---|---|
| Fresher or campus hire | Questions 1 to 50: keys, joins, ACID, normal forms | Shards, WAL and crash fixes |
| Backend developer | Locks, indexes, query plans | Normal forms past 3NF |
| Data analyst | Joins, views, star schemas | Locks and crash fixes |
| DBA | Backups, replicas, speed and access | ER diagram theory |
| Data engineer | Warehouses, ETL, NoSQL | Cursors and triggers |
Campus drives at service firms lean hard on normal forms and keys, so freshers should not skip questions 28 to 40. Senior backend rounds, however, rarely ask for 4NF. They want a real story about a deadlock or a slow query you fixed. If you plan to move into reporting work, our guide on becoming a data analyst without a degree covers the SQL and tools side.
Read also: 200 React Interview Questions With Answers
Pay and Demand for Database Jobs
In the US, database administrators and architects earned a median of $126,760 a year in May of last year. The split is wide, though. Database administrators had a median of $104,620, while database architects had a median of $139,500.

The outlook is also uneven. The BLS expects 0% job growth for administrators but 9% for architects in the decade to 2035. So the market rewards people who design systems more than people who only keep them running. If you get an offer, our salary negotiation email template helps you ask for more in writing.
Quick Answers on Database Interview Prep
How long does it take to prepare for a database interview?
For a fresher with some SQL, two to three weeks of daily practice is usually enough to cover these 100 questions. Spend half that time writing real queries on a local PostgreSQL or MySQL install. Answers stick better when you have seen them run.
Should I learn MySQL or PostgreSQL for interviews?
Either works, since the core ideas are the same. PostgreSQL follows the SQL standard more closely and has more index types. MySQL is common in Indian startups and web stacks. Learn one well, then read up on how the other handles isolation and indexes.
Do database interviews include live coding?
Most do. Expect to write two to five SQL queries on a shared screen or a site like HackerRank. Interviewers watch how you think, so say your plan before you type, and test with a small sample.
Which GUI tool should I practice with?
Any tool that shows query plans and lets you browse tables is fine. Our TablePlus vs DBeaver comparison covers two popular picks, one paid and one free. Still, practice some queries in the plain command line too, since some interviews use it.





















































































































