Relational Database Design and Normalization Interview Questions
261 multiple-choice tech interview questions on Relational Database Design and Normalization: keys, relationships, 1NF to BCNF, anomalies, denormalization. Written for technical phone screens and interview prep, organized by subtopic, with a short explanation for every answer. Learn the 239 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 1.1 Keys and constraints
- 1.2 Relationships and referential integrity
- 1.3 Functional dependencies and 1NF to 3NF
- 1.4 BCNF, 4NF, 5NF and decomposition
- 1.5 Anomalies and denormalization trade-offs
- 1.6 Data types, NULLs and column design
- 1.7 Entity-relationship modeling
- 1.8 Common schema design patterns
- 1.9 Schema evolution, naming and design reviews
Key terms
1.1 Keys and constraints
- Primary key
- Column(s) that uniquely identify each row and cannot be NULL
- Foreign key
- Column(s) whose values must match a key in another (or the same) table
- Surrogate key
- A system-generated key with no business meaning, such as an identity column or UUID
- Junction table
- A table that resolves a many-to-many relationship with a foreign key to each side
- Entity integrity
- Unique, non-null PK
- Superkey
- Any identifying set
- Alternate key
- Unchosen candidate key
- Stable primary key
- Never changes
- Email as key
- Changes and reuse
- National IDs
- Sensitive and unreliable
- Natural key uniqueness
- Unique constraint
- Identity vs sequence
- Column vs generator
- NOT NULL by default
- Fewer missing values
- DEFAULT constraint
- Value when omitted
- Multi-column CHECK
- Compare columns
- CHECK limits
- Current row only
- Allowed values
- CHECK IN or lookup
- Constraint names
- Clear errors
- Database-enforced rules
- All writers obey
- Generated column
- Derived value
- WITH NOCHECK
- Untrusted constraint
- Smart key
- Embedded meaning
- Primary key on every table
- Reliable identity
- Prime attribute
- Part of a candidate key
- SQL assertion
- Database-wide constraint
- Empty strings
- Bypass NOT NULL
- Surrogate for references
- One small column
1.2 Relationships and referential integrity
- One-to-many FK
- On the many side
- Default FK action
- Delete fails
- ON DELETE SET NULL
- Keep orphaned children
- ON UPDATE CASCADE
- Propagate key changes
- Cascade danger
- Mass deletes
- NO ACTION vs RESTRICT
- Deferred vs immediate
- Junction primary key
- Pair of FKs
- Relationship attributes
- In junction table
- Optional relationship
- Nullable FK
- Shared primary key
- Strict one-to-one
- One-to-one split
- Separate columns
- Hierarchy cycles
- Self-reference risk
- FK to unique column
- Allowed
- Composite foreign key
- Matching columns
- Cross-database references
- App-level checks
- Orphan row
- Missing parent
- FK type matching
- Same types
- Ternary relationship
- Three-way table
- Disabled foreign keys
- Bulk load risk
- Ordered junction
- Position column
- Circular references
- Deferred checks
- Follow graph
- Self-junction
- Symmetric pairs
- Canonical order
- MATCH FULL
- All or nothing
- Cascade path limits
- SQL Server rule
1.3 Functional dependencies and 1NF to 3NF
- First normal form (1NF)
- Every column holds one atomic value, with no repeating groups
- Second normal form (2NF)
- 1NF plus no partial dependency of a non-key column on part of a composite key
- Third normal form (3NF)
- 2NF plus no transitive dependencies: non-key columns depend only on the key
- Functional dependency
- A → B: each value of A determines exactly one value of B
- Normalization goal
- Each fact once
- 1NF
- Atomic values, no repeating groups
- 2NF
- No partial dependencies
- Transitive dependency
- A → B → C
- Trivial FD
- Right side in left
- Armstrong's axioms
- Derivation rules
- Attribute closure
- Everything determined
- Superkey test
- Closure covers all
- FDs from rules
- Data can't prove them
- Atomicity
- Depends on use
- ZipCode → City
- Transitive in theory
- Derived values
- Can drift
- Birth date over age
- Derivable
- Determinant
- Left side of FD
- Minimal cover
- No redundancy
- Transitivity rule
- A → C
- Augmentation rule
- AC → BC
- Decomposition rule
- Split right side
- Key from FDs
- Closure
- All-key table
- At least 3NF
- UNF
- Before 1NF
1.4 BCNF, 4NF, 5NF and decomposition
- BCNF violation
- Non-superkey determinant
- BCNF fix
- Split X → Y out
- 3NF guarantee
- Lossless and preserving
- Lossless join
- Exact rejoin
- Spurious rows
- Lossy split
- Binary lossless test
- Shared columns are a key
- Dependency preservation
- Checkable in one table
- FD vs MVD
- Every FD is an MVD
- 5NF
- Join dependencies
- Three-way rule
- Three pair tables
- 6NF
- Key plus one attribute
- DKNF
- Domains and keys
- Normal form order
- 3NF < BCNF < 4NF < 5NF
- Non-overlapping keys
- 3NF is BCNF
- 3NF synthesis
- From minimal cover
- 3NF in practice
- Usual target
- Prime exception
- 3NF allows
- Over-decomposition
- Joins without gain
- Chase test
- Lossless check
- Projection and join
- Split and recombine
- Two-column table
- Always BCNF
- Boyce and Codd
- 1974
- Edgar F. Codd
- Relational model, 1970
- 4NF in practice
- Rarely violated
1.5 Anomalies and denormalization trade-offs
- Update anomaly
- Inconsistency caused by changing a fact stored redundantly in only some places
- Denormalization
- Deliberately adding redundancy to speed up reads at the cost of write complexity
- Normalize first
- Denormalize when measured
- Counter column
- Must stay in sync
- Same-transaction sync
- Trigger or update
- Copied parent key
- Must match
- Composite FK check
- Enforces copy
- Anomaly query
- Disagreeing copies
- Redundancy symptom
- Conflicting values
- Cache vs denormalize
- Disposable vs data
- Over-normalization
- Too many joins
- Source of truth
- One owner
- Three anomalies
- Insert, update, delete
- Replication vs denormalization
- Copies vs schema
- Hot parent row
- Counter contention
- Write-heavy data
- Poor fit
- Storage effect
- Usually smaller
- Trigger bypass
- Drift
- Recompute job
- Repair drift
- Search documents
- Denormalized
- Name parts
- FullName drift
- Immutable copies
- Can't drift
- Controlled redundancy
- Owned and synced
- Tune before denormalizing
- Plans and indexes
1.6 Data types, NULLs and column design
- NUMERIC for money
- Exact arithmetic
- Precision and scale
- NUMERIC(10, 2)
- SQL Server money
- Fixed scale quirks
- timestamptz
- Absolute instant
- datetimeoffset
- Instant with offset
- datetime2
- Better datetime
- Future local times
- Store the zone
- varchar(255) habit
- Pick real limits
- text vs varchar(n)
- Same speed
- nvarchar
- UTF-16
- utf8mb4
- Full Unicode
- bit
- SQL Server boolean
- Nullable boolean
- Three states
- Status over flags
- No contradictions
- Fixed value sets
- CHECK, lookup or enum
- PostgreSQL enum
- Hard to remove values
- Overloaded NULL
- Ambiguous meaning
- CHECK and NULL
- UNKNOWN passes
- Sentinel values
- Fake data
- bigint keys
- Past 2.1 billion
- Phone as text
- Not a number
- double precision
- Measurements
- time type
- Time of day
- Duration storage
- interval or unit count
- DEFAULT now()
- Insert time
- char(n) padding
- Spaces
- inet and cidr
- Network types
- Range types
- Periods
- CREATE DOMAIN
- Reusable constrained type
1.7 Entity-relationship modeling
- ER diagram
- Entities and relationships
- Fan trap
- Ambiguous fan-out
- Cardinality vs optionality
- Maximum vs required
- Crow's foot circle
- Zero
- Two bars
- Exactly one
- Chen shapes
- Rectangle, diamond, oval
- Peter Chen
- ER model, 1976
- Model levels
- Conceptual, logical, physical
- Weak entity
- Needs its owner
- Identifying relationship
- Parent key in child PK
- Composite attribute
- Has parts
- Derived attribute
- Dashed oval
- Supertype/subtype
- Specialization
- Single-table inheritance
- Nullable columns
- Table-per-type
- Joins
- Table-per-concrete-class
- UNION ALL
- Disjoint vs overlapping
- One or several
- Total specialization
- Must be a subtype
- Attribute to entity
- Own attributes
- Verb labels
- Readable rules
- Chasm trap
- Optional path gaps
- Data dictionary
- Attribute meanings
- IDEF1X
- Modeling standard
- Expert review
- Catch cardinalities
- Reverse engineering
- From catalog
- Chen key
- Underlined
- Assignment history
- Own entity
- Role name
- How it participates
1.8 Common schema design patterns
- Adjacency list
- ParentId
- Adjacency drawback
- Recursion
- Nested sets
- Left and right numbers
- Nested set drawback
- Renumbering
- Materialized path
- Ancestor path
- Path prefix query
- LIKE '/1/4/%'
- ltree
- PostgreSQL paths
- hierarchyid
- SQL Server trees
- Closure table
- Ancestor pairs
- Polymorphic association
- No real FK
- Exclusive arc
- One of several FKs
- EAV
- Entity, attribute, value
- EAV cost
- No types or constraints
- JSONB extras
- EAV alternative
- One true lookup table
- Generic codes
- Audit triggers
- Automatic history
- FOR SYSTEM_TIME AS OF
- Point-in-time read
- Valid vs system time
- True vs recorded
- Bitemporal
- Both timelines
- Soft delete cost
- Filters everywhere
- Archive table
- Soft delete alternative
- Multi-tenancy models
- Shared, schema, database
- Row-level security
- Tenant filter
- Tenant in FKs
- No cross-tenant links
- Status history
- Every change
- Ledger
- Append-only entries
- Translations table
- Per language
- Party model
- People and organizations
1.9 Schema evolution, naming and design reviews
- Migrations in Git
- Same schema everywhere
- Never edit applied
- Write a new one
- Flyway and Liquibase
- History table
- State-based tools
- Diff to target
- Zero-downtime rename
- Expand and contract
- Compatibility view
- Old name keeps working
- Safe NOT NULL add
- Nullable, backfill, enforce
- PostgreSQL 11 defaults
- No rewrite
- NOT VALID
- New rows only
- VALIDATE CONSTRAINT
- Later, lighter lock
- Batched backfill
- Short transactions
- gh-ost
- Online MySQL changes
- Dropping columns
- Stop use first
- Down migrations
- Can't restore data
- Roll forward
- Fix with new migration
- Naming convention
- Consistency
- Quoted identifiers
- Case folding
- Singular vs plural
- Be consistent
- Reserved words
- Need quoting
- FK column names
- CustomerId
- Boolean names
- is_ or has_
- Units in names
- duration_seconds
- COMMENT ON
- Catalog docs
- Design review
- Keys and constraints first
- Migration linting
- Squawk
- Production-sized tests
- Real lock times
- Schema drift
- Environments differ
- Column type change
- Rewrite risk
- Data vs schema changes
- Separate steps
Sample practice questions
What is a primary key?
- Any column that has an index defined on it
- A column that references a row in another table
- Columns that uniquely identify each row and can't be NULL
- The first column listed in the CREATE TABLE statement
Answer: C. Columns that uniquely identify each row and can't be NULL A primary key is unique and NOT NULL. A table has at most one primary key, though it can span several columns.
A Students table and a Courses table have a many-to-many relationship. How is this normally modeled in a relational schema?
- A comma-separated list of course IDs stored in a column on the Students table
- A single foreign key column from Courses to Students, and nothing else
- A junction table with a foreign key to each, like Enrollments(StudentId, CourseId)
- Merging both tables into one wide table with a row per student and course
Answer: C. A junction table with a foreign key to each, like Enrollments(StudentId, CourseId) A junction table turns one many-to-many relationship into two one-to-many relationships, and its composite key prevents duplicate pairs.
A table stores PhoneNumbers as "555-1234, 555-9876" in a single column. Which normal form does this violate?
- 1NF, since the column isn't atomic
- 2NF, since there's a partial dependency
- 3NF, since there's a transitive dependency
- BCNF, since a determinant isn't a key
Answer: A. 1NF, since the column isn't atomic 1NF requires each column to hold a single atomic value and no repeating groups. Move phone numbers to their own table.
How does Boyce-Codd normal form (BCNF) differ from 3NF?
- BCNF allows repeating groups in a column, which 3NF strictly forbids
- Every determinant must be a superkey, closing a 3NF gap with overlapping keys
- BCNF only applies to tables that don't have any foreign keys at all
- BCNF is a weaker form that still permits transitive dependencies
Answer: B. Every determinant must be a superkey, closing a 3NF gap with overlapping keys Most tables in 3NF are already in BCNF. The difference shows up only with multiple overlapping candidate keys.
What is an update anomaly?
- A query that returns its rows in an unexpected order
- An UPDATE statement that runs slower than a SELECT
- An UPDATE that violates a CHECK constraint and fails
- A fact stored in many rows gets changed in only some of them
Answer: D. A fact stored in many rows gets changed in only some of them Redundancy causes update anomalies. Normalization stores each fact once to prevent them.
Why store money in `NUMERIC` or `DECIMAL` rather than `FLOAT`?
- Floating-point columns can't store negative numbers at all
- Floats can't be indexed in most relational databases
- Decimal columns always use less storage than floats
- Exact decimal arithmetic avoids binary rounding errors in sums
Answer: D. Exact decimal arithmetic avoids binary rounding errors in sums Floats suit measurements, not ledgers.
An entity-relationship (ER) diagram shows a "crow's foot" at one end of a relationship line. What does it indicate?
- The "many" side of the relationship
- That the relationship is optional on both sides
- A primary key column
- A deleted entity
Answer: A. The "many" side of the relationship Crow's foot notation marks the many side with three prongs; a single bar means one, and a circle means zero (optional).
A developer stores tags for a blog post as a JSON array column in PostgreSQL instead of a PostTags table. What is the main tradeoff?
- PostgreSQL can't index JSON columns, so every query scans the table
- Simpler whole-list access, but weaker integrity and cross-post queries
- It automatically puts the table into fourth normal form
- It turns the column into a foreign key to a hidden tags table
Answer: B. Simpler whole-list access, but weaker integrity and cross-post queries JSON columns (with GIN indexes in PostgreSQL) can work well, but you lose the foreign keys and constraints a junction table gives you.
Why keep migrations in version control and apply them in order?
- Ordered migrations always run faster than ad hoc changes
- Databases refuse any change that isn't stored in Git
- It removes the need to back up the database before deploys
- Every environment then reaches the same schema the same way
Answer: D. Every environment then reaches the same schema the same way The schema becomes reviewable code.
What is the difference between a natural key and a surrogate key?
- A natural key is always numeric, while a surrogate key is always text
- A surrogate key must be composite, while a natural key must be one column
- They're two names for the same thing, used interchangeably by designers
- A natural key has business meaning, like an ISBN; a surrogate is a generated ID
Answer: D. A natural key has business meaning, like an ISBN; a surrogate is a generated ID Surrogate keys stay stable when business data changes, which is why many designs use them as the primary key and put a unique constraint on the natural key.
More Storage and Data
- SQL Queries, Joins and Window Functions
- Indexing and Query Optimization
- Transactions, ACID and Isolation Levels
- NoSQL Databases: Document, Key-Value, Wide-Column and Graph
- Caching: Redis, CDNs and Cache Invalidation
- ORMs: Entity Framework Core and Hibernate
- Data Warehousing and ETL
- Message Queues and Event Streaming: Kafka, RabbitMQ and Service Bus
- Blob and Object Storage
- Backups, Replication and Disaster Recovery