Skip to content

Database Administrator interview questions

100 real questions with model answers and explanations for Junior candidates.

See a Database Administrator resume example

Practice with flashcards

Spaced repetition · Hunter Pass

Questions

database

A relational database stores structured data in tables and represents relationships between those tables through keys.

  • Each table models one kind of entity or relationship using named columns.
  • Rows contain individual records that follow the table's declared structure.
  • SQL is used to define, query, and change the data.
  • Constraints let the database enforce rules such as uniqueness and referential integrity.

Why interviewers ask this: The interviewer checks whether the candidate understands the table, relationship, SQL, and constraint foundations of the relational model.

schema

A table represents a relation, a row represents one tuple or record, and a column represents one named attribute.

  • Every column has a declared data type and may also have constraints.
  • Each row supplies values for the table's columns, including NULL where allowed.
  • Rows have no guaranteed display order unless a query uses ORDER BY.
  • A key can identify one row uniquely or connect it to a row in another table.

Why interviewers ask this: A strong answer uses the basic relational terms correctly and does not assume natural row ordering.

databaseschema

A database schema is the defined structure and organization of database objects.

  • It includes tables, columns, data types, keys, constraints, views, and indexes.
  • In systems such as PostgreSQL, a schema is also a named namespace inside a database.
  • Schema definitions describe allowed structure rather than the current rows stored in it.
  • Changes to that structure are commonly managed through versioned migrations.

Why interviewers ask this: The interviewer evaluates whether the candidate distinguishes database structure from the data instances it contains.

database

A key is one column or a set of columns used to identify rows or define relationships.

  • A candidate key can uniquely identify a row.
  • One candidate key is chosen as the primary key.
  • A foreign key references a candidate or primary key in another or the same table.
  • A composite key uses more than one column when uniqueness depends on their combination.

Why interviewers ask this: A strong answer distinguishes candidate, primary, foreign, and composite keys without treating every identifier as the same concept.

primary-keys

A primary key is the chosen column or column set that uniquely identifies every row in a table.

  • Its values must be unique across all rows in the table.
  • Primary-key columns cannot contain NULL.
  • A table has one primary-key constraint, though that key may contain multiple columns.
  • Database engines normally create an index to enforce or support the primary key.

Why interviewers ask this: The interviewer checks whether the candidate knows the uniqueness, nullability, and composite-key properties of a primary key.

foreign-keys

A foreign key enforces that referenced values correspond to an existing candidate key in another or the same table.

  • An orders.customer_id foreign key can reference customers.id.
  • It prevents inserting a non-NULL reference with no matching parent row.
  • It also controls what happens when a referenced row is updated or deleted.
  • The constraint enforces referential integrity inside the database rather than relying only on application code.

Why interviewers ask this: A strong answer explains both the relationship and the integrity guarantee provided by a foreign key.

primary-keys

Both enforce uniqueness, but a primary key is the table's main row identifier while UNIQUE defines additional candidate keys.

  • A table can have only one primary-key constraint and multiple UNIQUE constraints.
  • Primary-key columns are always NOT NULL.
  • NULL handling in UNIQUE constraints varies by database engine and configuration.
  • Foreign keys can reference a suitable UNIQUE key as well as a primary key.

Why interviewers ask this: The interviewer evaluates whether the candidate understands identity, nullability, and multiple alternate keys.

fundamentals

These constraints define allowed or automatically supplied column values.

  • NOT NULL rejects rows where the column has no value.
  • CHECK requires a Boolean condition such as price >= 0 to be satisfied.
  • DEFAULT supplies a value when an INSERT omits the column.
  • A default does not override an explicitly provided value and does not validate existing business relationships.

Why interviewers ask this: A strong answer distinguishes required values, validation expressions, and insertion defaults.

foreign-keysfundamentals

These actions define how a child reference responds when its parent row is deleted.

  • RESTRICT or NO ACTION prevents deletion while matching child rows remain.
  • CASCADE automatically deletes the referencing child rows.
  • SET NULL clears the foreign-key value and therefore requires that column to allow NULL.
  • The choice must match ownership semantics because CASCADE can remove more data than one explicit DELETE names.

Why interviewers ask this: The interviewer checks whether the candidate understands referential actions and their data-model consequences.

database

Data types define the values a column can store, how those values are represented, and which operations are valid.

  • Integer, numeric, text, date, time, Boolean, and binary types express different domains.
  • An appropriate type lets the database validate input and compare values correctly.
  • Type choice affects range, precision, storage, sorting, and function behavior.
  • PostgreSQL and MySQL share many type concepts but differ in some names and semantics.

Why interviewers ask this: A strong answer connects data types to correctness and representation rather than treating them as storage labels.

These types store character data but differ in length rules and engine-specific behavior.

  • CHAR(n) is fixed length and may pad shorter values to the declared size.
  • VARCHAR(n) stores variable-length text up to a declared limit.
  • TEXT stores variable-length text without the same application-level length declaration.
  • PostgreSQL and MySQL differ in storage details, limits, and index rules, so their documentation remains authoritative.

Why interviewers ask this: The interviewer checks whether the candidate understands fixed and variable text semantics without assuming identical behavior across engines.

DECIMAL or NUMERIC should be used when exact decimal arithmetic matters, while floating-point types represent approximate values.

  • Monetary amounts commonly require exact precision and scale.
  • FLOAT and DOUBLE can introduce binary rounding differences in decimal calculations.
  • Approximate types suit scientific measurements where a range of values matters more than exact decimal representation.
  • Precision and scale should be chosen to cover valid values without silently discarding required detail.

Why interviewers ask this: A strong answer connects exact and approximate numeric representation to the correctness of stored values.

These types represent calendar dates, clock times, date-time values, and time-aware instants with different semantics.

  • DATE stores a calendar date without a time of day.
  • TIME stores a time of day without a date.
  • TIMESTAMP stores a date and time whose time-zone interpretation depends on the database type and application contract.
  • In PostgreSQL, timestamptz represents an instant normalized internally and displayed in the session time zone.

Why interviewers ask this: The interviewer evaluates whether the candidate treats temporal types by meaning rather than storing every time value as text.

sqlfundamentals

NULL represents a missing or unknown value and is not equal to any ordinary value, including another NULL.

  • Comparisons with NULL usually produce UNKNOWN rather than TRUE or FALSE.
  • IS NULL and IS NOT NULL test for its presence.
  • WHERE keeps only rows whose predicate evaluates to TRUE, so UNKNOWN rows are filtered out.
  • Functions and aggregates may handle NULL differently, so its semantics must be checked explicitly.

Why interviewers ask this: A strong answer understands SQL's three-valued logic and avoids testing NULL with the equality operator.

queries

A basic SELECT query chooses columns, a source, optional row conditions, grouping, group conditions, ordering, and a result limit.

  • SELECT defines the output expressions or columns.
  • FROM identifies tables or derived sources, and JOIN connects related sources.
  • WHERE filters rows before grouping, while GROUP BY and HAVING operate on groups.
  • ORDER BY sorts the final result, and LIMIT or FETCH restricts the number of returned rows.

Why interviewers ask this: The interviewer checks whether the candidate knows the role of each common query clause rather than only their syntax.

queries

WHERE filters input rows by keeping only those for which its predicate evaluates to TRUE.

  • Comparison operators test values, and AND, OR, and NOT combine conditions.
  • NULL comparisons can produce UNKNOWN and therefore do not pass the filter.
  • Parentheses make precedence explicit in compound predicates.
  • WHERE is applied before aggregate grouping, so aggregate conditions belong in HAVING.

Why interviewers ask this: A strong answer covers Boolean logic, NULL behavior, and the distinction between row and group filtering.

ORDER BY defines result order, LIMIT restricts row count, and OFFSET skips a number of rows.

  • ORDER BY can sort by one or more expressions in ascending or descending order.
  • Without ORDER BY, the database does not guarantee which rows appear first.
  • LIMIT is useful for bounded result sets, while OFFSET is often combined with LIMIT for simple pagination.
  • A stable pagination order requires enough sort columns to break ties consistently.

Why interviewers ask this: The interviewer evaluates whether the candidate understands deterministic ordering and bounded result sets.

sqlschema

Aliases give temporary names to output expressions or data sources within one query.

  • A column alias makes a calculated or renamed output easier to read.
  • A table alias shortens qualified references such as o.customer_id.
  • Aliases are especially useful when the same table appears more than once in a self-join.
  • An alias does not rename the underlying database object.

Why interviewers ask this: A strong answer explains aliases as query-scoped names rather than schema changes.

joins

An INNER JOIN returns combinations of rows that satisfy the join condition on both sides.

  • A common condition matches a foreign key to a referenced key.
  • Rows with no matching partner are excluded.
  • One row can appear in multiple result rows when it matches multiple rows on the other side.
  • The ON clause defines the relationship, while WHERE can further filter the joined result.

Why interviewers ask this: The interviewer checks whether the candidate understands matching behavior and possible row multiplication in joins.

joins

Outer joins retain unmatched rows from one or both sides and fill missing columns with NULL.

  • LEFT JOIN keeps every left row and matching right rows.
  • RIGHT JOIN keeps every right row and matching left rows.
  • FULL OUTER JOIN keeps unmatched rows from both sides.
  • A WHERE condition on the nullable side can accidentally remove unmatched rows and change the effective result.

Why interviewers ask this: A strong answer compares row preservation and recognizes how later filtering can undo outer-join behavior.

Locked questions

  • 21

    What are CROSS JOIN and self-join?

    joins
  • 22

    What does GROUP BY do?

    aggregation
  • 23

    What do COUNT, SUM, AVG, MIN, and MAX do?

  • 24

    What is the difference between WHERE and HAVING?

    queriesaggregation
  • 25

    What does DISTINCT do in a SELECT query?

    queriesdistinct
  • 26

    What is a subquery, and what is a common table expression?

    subqueries
  • 27

    What is the difference between UNION and UNION ALL?

    union
  • 28

    What is database normalization?

    databasenormalization
  • 29

    What is First Normal Form?

    forms
  • 30

    What is Second Normal Form?

    forms
  • 31

    What is Third Normal Form?

    forms
  • 32

    What are insertion, update, and deletion anomalies?

  • 33

    What is a database index?

    databaseindexes
  • 34

    How does a B-tree index work at a high level?

    indexes
  • 35

    What is the difference between clustered and nonclustered indexes?

    indexes
  • 36

    What is a composite index, and why does column order matter?

    indexesschema
  • 37

    How do a unique index and a UNIQUE constraint relate?

    indexes
  • 38

    What is a database transaction?

    databasetransactions
  • 39

    What does ACID mean?

    acid
  • 40

    What are COMMIT, ROLLBACK, and SAVEPOINT used for?

    rollback
  • 41

    What are the standard SQL transaction isolation levels?

    sqltransactions
  • 42

    What are dirty reads, non-repeatable reads, and phantom reads?

  • 43

    What is a database view?

    database
  • 44

    How does a materialized view differ from a regular view?

    materialized-views
  • 45

    What is the difference between a database user and a role?

    database
  • 46

    What do GRANT and REVOKE do, and what is the principle of least privilege?

    least-privilege
  • 47

    What is the difference between logical and physical database backups?

    databasebackups
  • 48

    How do full, incremental, and differential backups differ?

    backups
  • 49

    What are primary and replica databases?

    databasereplication
  • 50

    How do synchronous and asynchronous replication differ?

    replicationasync
  • 51

    How would you find customers who have never placed an order?

  • 52

    How would you return the most recent order for each customer?

  • 53

    How would you write a query that reports total paid sales by month?

    queries
  • 54

    A users table may contain duplicate email addresses. How would you find them?

  • 55

    You must update prices for one supplier without touching other products. How would you do it safely?

  • 56

    How would you delete duplicate rows while keeping the oldest record?

    dedup
  • 57

    An orders page becomes slow at high page numbers. How would you change its query?

    queries
  • 58

    A report misses rows where discount is NULL. How would you correct the calculation and filter?

    fundamentals
  • 59

    How would you list each order with the customer name and optional shipping address?

  • 60

    How would you return the three highest-paid employees in each department?

  • 61

    A query filters a timestamp with date(created_at) and ignores an existing index. How would you rewrite it?

    indexesqueries
  • 62

    How would you show paid, failed, and pending order counts in one query?

    queries
  • 63

    How would you insert a daily metric but update it if that date already exists?

    monitoring
  • 64

    How would you implement a transfer between two account balances in SQL?

    sql
  • 65

    An application builds SQL by concatenating a user search string. How would you make it safe?

    sql
  • 66

    EXPLAIN shows a sequential scan on a large table for a selective filter. What would you check first?

  • 67

    A query plan estimates ten rows but actually returns one hundred thousand. What would you do?

    estimationqueries
  • 68

    A frequent query filters users by email. Which index would you choose?

    indexesqueries
  • 69

    A query filters orders by customer_id and sorts newest first. What index would you consider?

    indexesqueries
  • 70

    There is an index on status, created_at, but a query filtering only created_at does not use it. How would you respond?

    indexesqueries
  • 71

    Most orders are completed, but a frequent job selects only pending orders. What index might help?

    indexes
  • 72

    How would you prevent two users from registering the same username during concurrent requests?

    concurrency
  • 73

    A query has an index on the filtered column but PostgreSQL still chooses a sequential scan. Is that always a problem?

    indexesqueriespostgres
  • 74

    A lookup uses an index but still reads the table for two returned columns. How might you reduce that work?

    indexesschema
  • 75

    A table has many overlapping indexes and writes are slowing down. How would you clean them up?

    indexes
  • 76

    A dashboard repeatedly runs a slow COUNT(*) on a large filtered table. How would you improve it?

  • 77

    An application loads 100 orders and then sends one customer query per order. How would you reduce the database work?

    databasequeries
  • 78

    EXPLAIN ANALYZE shows a sort spilling to disk. What would you check?

  • 79

    How would you design a simple schema for customers and their orders?

    schemadesign
  • 80

    How would you model products that can belong to many categories?

  • 81

    A table needs created and last-updated timestamps. How would you implement them reliably?

  • 82

    A product should disappear from normal queries but remain for audit. How would you design soft deletion?

    queriesdesign
  • 83

    Which columns and constraints would you choose for a simple payment record?

    schema
  • 84

    Customer rows repeat the same country and city text many times. Would you normalize those values into separate tables?

    normalization
  • 85

    How would you choose what happens to orders when a customer row is deleted?

  • 86

    How would you add a required column to a large populated table with minimal risk?

    schema
  • 87

    How would you take and restore a logical PostgreSQL backup for one database?

    databasepostgresbackups
  • 88

    A table was accidentally deleted, but the rest of the production database has new writes. How would you restore it?

    databaserest
  • 89

    How would you recover PostgreSQL to a time just before an accidental update?

    postgres
  • 90

    How would you prove that scheduled database backups can actually be restored?

    databasebackups
  • 91

    How would you create a MySQL logical backup while reducing impact on a busy transactional database?

    databasetransactionsbackups
  • 92

    How would you back up a SQLite database that an application is actively using?

    database
  • 93

    A PostgreSQL restore succeeds, but the application gets permission denied errors. What would you check?

    postgres
  • 94

    One PostgreSQL session is waiting on a lock. How would you find the blocking session?

    postgressessions
  • 95

    Two transactions deadlock while updating the same pair of tables. How would you reduce the chance of recurrence?

    transactionslocking
  • 96

    An application leaves transactions open for hours. What problems would you investigate?

    transactions
  • 97

    A PostgreSQL table has many updates and dead tuples. What maintenance would you perform?

    postgres
  • 98

    When would you use REINDEX on a PostgreSQL index, and how would you do it safely?

    indexespostgres
  • 99

    Queries become slower after a large data import. How would you check whether statistics are the cause?

    queries
  • 100

    What would you monitor first for a small PostgreSQL production database?

    databasepostgresmonitoring