DBMS & SQL chapters
  1. 01Database Concepts & Relational Architecture
  2. 02Comprehensive SQL Engine & Joins
  3. 03Functional Dependencies & Normalization
  4. 04Transactions & Concurrency Control
  5. 05Indexing, B+ Trees & NoSQL Systems

Chapter 1 · Database Systems

Database Concepts & Relational Architecture

5 topics in 4 parts

Key ideas

External View 1 (Web User Portal) External View 2 (Finance & Billing) External View 3 (Analytics & BI) ↕ LOGICAL DATA INDEPENDENCE ↕ CONCEPTUAL / LOGICAL SCHEMA LEVEL Entities, Relational Tables, Attributes, Constraints, Foreign Keys & Business Rules ↕ PHYSICAL DATA INDEPENDENCE ↕ INTERNAL / PHYSICAL STORAGE LEVEL B+ Tree Indexes, Hashing, Page Blocks, Compression, Record Offsets & RAID Storage
Database Concepts & Relational Architecture
Evaluation ParameterStandard Relational PatternProduction Optimization Impact
Storage Engine LayerDisk page blocks & buffer pool cacheMinimizes random disk I/O via sequential prefetching
Index UtilizationB+ Tree logarithmic search $O(\log N)$Avoids full table scans across millions of rows
Concurrency & LocksRow-level shared (S) and exclusive (X) locksPrevents race conditions while maximizing read throughput
Failure RecoveryWrite-Ahead Logging (WAL) / Undo-RedoGuarantees durability and instant crash recovery
Level / TierGoverning RoleTarget AudiencePrimary Definition ToolIndependence Guarantee
External (View) LevelVirtual schema projectionsEnd-users, Web Apps, BI analystsSQL CREATE VIEW queriesIsolates user apps from schema evolution
Conceptual (Logical) LevelEntities, relationships, constraintsDatabase Administrators (DBA), Software ArchitectsSQL DDL (CREATE TABLE, ALTER)Logical Data Independence (protects views)
Internal (Physical) LevelBlock allocation, indexes, B+ treesStorage Engine Developers, System DBAsStorage Engine / OS File ManagementPhysical Data Independence (protects conceptual schema)

DBMS Architecture Interview Problem: Physical vs Logical Independence

Question: Why is Logical Data Independence significantly harder to achieve than Physical Data Independence in production database systems? Answer: In Physical Data Independence, internal optimizations (like adding an index or moving table files to a faster SSD) do not alter the column names, constraints, or relations at all; the logical schema remains 100% identical. However, in Logical Data Independence, changes to the conceptual schema (such as partitioning an `Employees` table into `Emp_Personal` and `Emp_Job` to remove nulls) require modifying the view mappings or adding triggers/updatable view rules. If an external view involves complex joins across altered tables, keeping it fully updatable without breaking legacy client queries requires substantial mapping overhead.

Executable Code Blueprint & Implementation (DBMS & SQL)

-- Relational Keys Implementation in SQL DDL
CREATE TABLE Departments (
    dept_id INT PRIMARY KEY,              -- Primary Key
    dept_name VARCHAR(50) NOT NULL UNIQUE -- Alternate Key
);

CREATE TABLE Students (
    student_id INT,                      -- Candidate Key 1
    roll_no VARCHAR(20),                 -- Candidate Key 2
    email VARCHAR(100),                  -- Candidate Key 3
    phone VARCHAR(15),
    dept_id INT,                         -- Foreign Key referencing Departments
    
    -- Designate Primary Key
    CONSTRAINT pk_student PRIMARY KEY (student_id),
    
    -- Designate Alternate Keys with UNIQUE constraints
    CONSTRAINT uq_roll UNIQUE (roll_no),
    CONSTRAINT uq_email UNIQUE (email),
    
    -- Foreign Key Constraint enforcing Referential Integrity
    CONSTRAINT fk_student_dept FOREIGN KEY (dept_id) 
        REFERENCES Departments(dept_id) 
        ON DELETE CASCADE ON UPDATE CASCADE
);
SUPER KEY (Superset of attributes uniquely identifying a tuple) CANDIDATE KEY (Minimal Super Key with NO redundant attributes) PRIMARY KEY Selected by DBA (NOT NULL + UNIQUE) e.g. Student_ID (Roll_No) ALTERNATE / SECONDARY Unchosen Candidate Keys e.g. Passport_No, Email
Database Concepts & Relational Architecture

Relational Key Types Comparison Matrix

Key TypeDefinitionAllows NULL?Multiplicity in TableMinimality Requirement
Super KeyAny attribute combination guaranteeing unique rowsDependent on attributesUnlimited possible subsetsNo (can contain redundant columns)
Candidate KeyMinimal super key with zero redundant attributesStrictly UNIQUE (rarely null)One or more per tableYes (Strictly minimal)
Primary KeyThe designated unique identifier chosen by DBASTRICTLY NO (NOT NULL enforced)Exactly ONE per tableYes (Must be a Candidate Key)
Foreign KeyReferences Primary Key of another relationYes (unless defined NOT NULL)Zero, one, or multipleMatches referenced parent key

Relational Design Interview Problem: Minimal Super Key Derivation

Question: Given a relation $R(A, B, C, D)$ with functional dependencies $A \to B, B \to C, C \to D$. Find all candidate keys. Answer: Compute attribute closure of $A$: $A^+ = \{A, B, C, D\}$. Since $A^+$ includes all attributes of $R$, $A$ is a Super Key. Since $A$ is a single attribute, no subset can be removed, making $A$ minimal. Therefore, $A$ is the sole Candidate Key.

Checkpoint

1. What distinguishes a Candidate Key from a general Super Key?

All 5 topics in Database Concepts & Relational Architecture

  1. Foundations

    • File System vs DBMS
  2. Architecture

    • 3-Tier Schema Architecture
    • Data Independence
  3. Data Modeling

    • ER Modeling & Cardinality
  4. Relational Model

    • Database Keys