0% revised

DBMS

Interview essentials · SQL · normalization · transactions

0 / 12 revised
DBMS vs RDBMS 🎯
DBMS
▾
Quick Recall
RDBMS = DBMS + relational model + ACID + SQL
FeatureDBMSRDBMS
ModelFile-based, hierarchical, networkRelational (tables)
ACIDNot guaranteedGuaranteed
NormalizationNot enforcedEnforced
RelationshipsNo formal supportForeign keys
ExamplesXML stores, flat filesMySQL, PostgreSQL, Oracle
3-Schema Architecture: External (user views) → Conceptual (logical structure) → Internal (physical storage). Provides data independence.
Keys 🎯
DBMS
▾
Quick Recall
Super ⊇ Candidate ⊇ Primary; Foreign links tables
KeyDefinition
Super KeyAny set of attributes that uniquely identifies a row
Candidate KeyMinimal super key (no redundant attributes)
Primary KeyChosen candidate key; NOT NULL + UNIQUE
Foreign KeyReferences PK of another table; enforces referential integrity
Composite KeyPK made of 2+ columns together
Alternate KeyCandidate keys not chosen as PK
ER Model & Mapping
DBMS
▾
Quick Recall
Entity = table, Attribute = column, Relationship = FK
ER Components: Entity (rectangle), Attribute (oval), Relationship (diamond).
Cardinality: 1:1, 1:N, M:N.
Mapping rules:
  • Strong entity → table with PK
  • Weak entity → table with partial key + owner FK (composite PK)
  • 1:1 → FK on either side (prefer total participation side)
  • 1:N → FK on N-side
  • M:N → new junction table with both FKs as composite PK
  • Multivalued attribute → separate table
Normalization 🎯
DBMS
▾
Quick Recall
1NF→2NF→3NF→BCNF: remove partial, transitive, and overlapping candidate key dependencies
FormRuleRemoves
1NFAtomic values, no repeating groupsMulti-valued cells
2NF1NF + no partial dependency on composite PKPartial dependencies
3NF2NF + no transitive dependency (non-prime → non-prime)Transitive dependencies
BCNFFor every FD X→Y, X must be a super keyOverlapping candidate keys
Example: Student(sid, sname, dept, dept_head)
FD: sid→sname,dept; dept→dept_head (transitive!)
Decompose: Student(sid,sname,dept) + Dept(dept,dept_head) → 3NF
Functional Dependencies
DBMS
▾
Quick Recall
X→Y means X uniquely determines Y; use Armstrong's axioms
Armstrong's Axioms:
  • Reflexivity: If Y⊆X then X→Y
  • Augmentation: If X→Y then XZ→YZ
  • Transitivity: If X→Y and Y→Z then X→Z
Derived: Union, Decomposition, Pseudo-transitivity.
Closure X⁺: All attributes determinable from X. Algorithm: start with X, repeatedly add RHS of any FD whose LHS ⊆ current set.
Canonical Cover: Minimal equivalent FD set — no redundant FDs or attributes.
SQL Quick Reference 🎯
DBMS
▾
Quick Recall
SELECT→FROM→JOIN→WHERE→GROUP BY→HAVING→ORDER BY→LIMIT
CategoryCommands
DDLCREATE, ALTER, DROP, TRUNCATE
DMLSELECT, INSERT, UPDATE, DELETE
DCLGRANT, REVOKE
TCLCOMMIT, ROLLBACK, SAVEPOINT
JOIN Types:
JoinReturns
INNERMatching rows in both tables
LEFT OUTERAll left + matched right (NULL if no match)
RIGHT OUTERAll right + matched left
FULL OUTERAll rows from both (NULLs where no match)
CROSSCartesian product
SELFTable joined with itself
Aggregates: COUNT, SUM, AVG, MIN, MAX — used with GROUP BY.
HAVING filters groups (WHERE filters rows before grouping).
Window: ROW_NUMBER() / RANK() / DENSE_RANK() OVER (PARTITION BY col ORDER BY col)
Indexing 🎯
DBMS
▾
Quick Recall
B+ tree = balanced, range-friendly; clustered changes row order, non-clustered doesn't
TypeClusteredNon-Clustered
Row orderData physically sorted by indexSeparate structure points to data
Count per tableOnly 1Multiple allowed
SpeedFaster range queriesExtra lookup (pointer → row)
Leaf nodesActual data rowsPointers to data
B+ Tree: Balanced tree where all data in leaf nodes (linked list for range scans). Internal nodes hold keys only. Height = O(log n) → fast lookups.
When to index: High-read, low-write columns used in WHERE/JOIN. Avoid on small tables or frequently updated columns.
Transactions & ACID 🎯
DBMS
▾
Quick Recall
Atomicity=all-or-nothing, Consistency=valid state, Isolation=no interference, Durability=survives crash
PropertyMeaningEnsured By
AtomicityTransaction fully completes or fully rolls backUndo log
ConsistencyDB moves from one valid state to anotherIntegrity constraints
IsolationConcurrent txns don't interfereConcurrency control (locks/MVCC)
DurabilityCommitted data survives crashesRedo log, WAL
Transaction states: Active → Partially Committed → Committed (or Failed → Aborted)
Concurrency Control 🎯
DBMS
▾
Quick Recall
2PL: grow locks then shrink; strict 2PL holds till commit
Problems: Lost update, dirty read, unrepeatable read, phantom read.
Lock types: Shared (read) — multiple allowed; Exclusive (write) — one only.
2-Phase Locking (2PL):
  • Growing phase: Acquire locks, no releases
  • Shrinking phase: Release locks, no new acquires
Guarantees serializability but can deadlock.
Strict 2PL: Hold all exclusive locks until commit/abort → prevents cascading rollbacks.
Deadlock handling: Wait-die / Wound-wait (age-based), timeout, or detect cycle in wait-for graph and abort youngest.
Isolation Levels & Anomalies 🎯
DBMS
▾
Quick Recall
Read Uncommitted→Read Committed→Repeatable Read→Serializable (strictness increases)
LevelDirty ReadNon-RepeatablePhantom
Read UncommittedYesYesYes
Read CommittedNoYesYes
Repeatable ReadNoNoYes
SerializableNoNoNo
Schedule types:
  • Serial: Txns execute one after another
  • Serializable: Equivalent result to some serial schedule (conflict/view)
  • Recoverable: If T2 reads from T1, T1 commits before T2
  • Cascadeless: Only read committed data
Query Optimization
DBMS
▾
Quick Recall
Query plan: parse→optimize→execute; indexes + join order matter most
Optimization techniques:
  • Push selections/projections down (reduce rows early)
  • Join ordering: smaller result sets first
  • Use indexes on WHERE/JOIN columns
  • Avoid SELECT * — fetch only needed columns
  • Subquery vs JOIN: JOINs often faster (optimizer can rewrite)
  • EXPLAIN/EXPLAIN ANALYZE to inspect query plans
Cost factors: Disk I/O (dominant), CPU, memory, network.
CAP Theorem & SQL vs NoSQL
DBMS
▾
Quick Recall
Pick 2 of 3: Consistency, Availability, Partition tolerance
CAP Theorem: In a distributed system, you can guarantee at most 2 of:
  • Consistency: All nodes see same data
  • Availability: Every request gets a response
  • Partition Tolerance: System works despite network failures
Since partitions are inevitable, choose CP (strong consistency, e.g. HBase) or AP (available, eventually consistent, e.g. Cassandra).
SQLNoSQL
SchemaFixed, predefinedDynamic, flexible
ScalingVerticalHorizontal
ACIDFullBASE (eventual consistency)
Best forComplex queries, transactionsBig data, real-time, unstructured