🗄️ Database Interview Questions
Master database interviews with questions on SQL, NoSQL, optimization, indexing, and database design
Explain database indexing and when to use different index types
HardIndexes improve query performance by creating data structures that allow faster lookups. However, they slow down writes and consume additional storage.
Common Index Types:
- B-Tree: Default index, good for equality and range queries
- Hash: Fast for equality comparisons, not for ranges
- GiST/GIN: Full-text search and complex data types
- Partial: Index on subset of rows
- Composite: Index on multiple columns
SQL
Explain ACID properties and implement a database transaction
MediumACID guarantees reliability of database transactions:
- Atomicity: All operations succeed or all fail (no partial updates)
- Consistency: Data remains valid according to rules/constraints
- Isolation: Concurrent transactions don't interfere with each other
- Durability: Committed data persists even after system failure
SQL
Compare SQL vs NoSQL databases and when to use each
MediumSQL (Relational) and NoSQL (Non-relational) databases have different strengths:
SQL (PostgreSQL, MySQL)
- Structured data, fixed schema
- ACID transactions
- Complex queries, JOINs
- Vertical scaling
- Strong consistency
NoSQL (MongoDB, Redis)
- Flexible/dynamic schema
- BASE (Basically Available, Soft state, Eventual consistency)
- Denormalized data
- Horizontal scaling
- High performance for specific use cases
SQL
JavaScript
JavaScript
Explain database normalization and denormalization with examples
MediumNormalization: Organizing data to reduce redundancy and improve integrity.Denormalization: Intentionally introducing redundancy for performance.
Normal Forms:
- 1NF: Atomic values, no repeating groups
- 2NF: 1NF + no partial dependencies
- 3NF: 2NF + no transitive dependencies
- BCNF: 3NF + stricter rules
SQL
Explain database query optimization techniques
HardQuery optimization improves performance by reducing execution time and resource usage.
SQL
Interview Tips for Database
- ✓ Understand when to use indexes and their tradeoffs
- ✓ Know ACID properties and transaction isolation levels
- ✓ Be familiar with both SQL and NoSQL databases
- ✓ Practice query optimization using EXPLAIN
- ✓ Understand normalization vs denormalization tradeoffs
- ✓ Know how to design schemas for different use cases
- ✓ Be ready to discuss scaling strategies (sharding, replication)