Course Overview
Why SQL Exists
A historical view of file storage, the relational model paper by Edgar F. Codd, and how SQL became standard.
Interview: Interviewers at FAANG companies often ask about the evolution of databases to test whether candidates understand why relational systems were needed over flat-file storage.
1. Introduction
SQL did not appear out of nowhere. It was born from decades of frustration with data storage systems that were fragile, slow, and impossible to maintain. To understand why SQL exists — and why it remains essential — you need to trace the journey from flat-file storage through hierarchical databases to the revolutionary relational model proposed by Edgar F. Codd in 1970.
Every modern database design decision — from normalization to ACID transactions — traces back to the failures of pre-relational storage systems. This topic walks you through the historical evolution that made SQL the universal language of data.
2. Why It Matters
Understanding why SQL was invented — rather than just how to write it — separates engineers who can use a tool from those who can make architectural decisions. When a system design interview asks "Why PostgreSQL over MongoDB?", the answer traces back to the same problems SQL was designed to solve.
- Legacy migration: Many enterprises still run COBOL/IMS systems. Understanding pre-relational models is essential when migrating these systems to modern SQL databases.
- Technology selection: Knowing the trade-offs that led to the relational model helps you choose the right database for new projects.
- Data integrity: SQL was created to prevent data corruption — a problem that cost businesses millions of dollars in the 1960s and still does today.
Interview Insight
FAANG interviewers frequently ask about the evolution of databases to test whether candidates understand why relational systems were needed. Demonstrating knowledge of flat-file and hierarchical limitations shows architectural maturity.
3. Real-World Analogy
Imagine a law firm in the 1950s that stores all client records in paper filing cabinets. The same client’s name and address appears in the case files cabinet, the billing cabinet, and the correspondence cabinet. When a client moves, a clerk must find and update every single copy across all cabinets. Miss one, and the firm sends a bill to the wrong address — or worse, loses track of an active case.
Now imagine a modern digital system where the client’s information is stored in exactly one place, and every case, bill, and letter simply references that single record. That is the revolution the relational model brought to data management — one source of truth, referenced everywhere.
4. How It Works
The journey to SQL happened in four distinct eras:
Era 1: Flat Files (1950s–1960s)
Data was stored in fixed-width text files. A bank might store customer records as lines in a file, with account number, name, and balance padded to exact character widths. Problems included massive data redundancy, no concurrent access, and program-data dependence — changing the file format broke every program that read it.
Era 2: Hierarchical and Network Models (1960s–1970s)
IBM developed IMS for the Apollo space program using a tree structure. CODASYL introduced a network (graph) model. Both required programmers to navigate data by following pointers from record to record — like traversing a linked list. Changing the physical layout broke every query.
Era 3: The Relational Revolution (1970)
Edgar F. Codd at IBM published "A Relational Model of Data for Large Shared Data Banks" in the ACM journal. His key insight: separate the logical structure of data from its physical storage. Data would be stored in tables (relations) with rows (tuples) and columns (attributes), accessed via a declarative language rather than navigational code.
Era 4: SQL Standardization (1974–Present)
IBM built System R, creating SEQUEL (later renamed SQL). The language became an ANSI standard in 1986 and has been continuously expanded with joins, window functions, JSON support, and more.
5. Internal Architecture
The SQL standardization process follows a rigorous pipeline involving multiple committees and years of review:
Each database vendor (PostgreSQL, MySQL, Oracle, SQL Server) implements the standard with proprietary extensions. PostgreSQL is widely considered the most standards-compliant, while MySQL and Oracle add significant vendor-specific features.
6. Visual Explanation
The diagram traces the evolution from flat-file storage through hierarchical and network databases to the relational model, showing the key problems each era solved — and the new problems each introduced.
7. Practical Example
Compare how the same query — finding all orders for a customer — would be written in pre-relational navigation versus SQL:
The SQL version is shorter, readable, and does not depend on the physical storage layout. The query optimizer automatically determines the most efficient access path — whether scanning an index, using a hash lookup, or parallelizing across multiple CPU cores.
8. Common Mistakes
- Assuming all SQL databases are identical: The ANSI SQL standard defines the baseline, but PostgreSQL, MySQL, Oracle, and SQL Server each add proprietary extensions. A
LIMITclause works in PostgreSQL but requiresTOPin SQL Server orFETCH FIRSTin Oracle. - Thinking the relational model is perfect: Codd’s 12 rules are aspirational — most commercial databases satisfy only a subset. The relational label is pragmatic, not absolute.
- Ignoring NULL semantics early: Codd’s Rule 3 requires systematic NULL handling, yet many developers discover
NULL = NULLreturns UNKNOWN only after a production bug.
Common Pitfall
Many engineers confuse SQL dialects. While the ANSI SQL standard exists, each vendor adds proprietary extensions. Always check your target database’s dialect before writing production queries.
9. Quick Quiz
Q1: Who published the foundational paper for the relational model?
A) Donald Chamberlin
B) Edgar F. Codd
C) Eric Brewer
D) Michael Stonebraker
Answer: B) Edgar F. Codd (1970)
Q2: What was SQL originally called before its current name?
A) QUERY-L
B) SEQUEL (Structured English Query Language)
C) DATALOG
D) RELANG
Answer: B) SEQUEL, renamed due to a trademark conflict
Q3: What critical flaw did hierarchical and network databases share?
A) They could not store numeric data
B) Navigation-based access — queries depended on physical storage paths
C) They required internet connectivity
D) They only supported single-user access
Answer: B) Navigation-based access coupled queries to physical storage
10. Scenario-Based Challenge
Challenge: The Insurance Company Migration
An insurance company stores policy data in COBOL flat files. A customer’s address appears in the policy file, the claims file, and the billing file. Last month, a customer moved but only the billing file was updated — resulting in a claim check sent to the wrong address.
Design a two-table relational schema (customers + policies) that prevents this problem. Write a SQL query that retrieves all policies for a customer by name, demonstrating how the relational model ensures a single source of truth for the address.
11. Debugging Exercise
The following query works in PostgreSQL but fails in MySQL. Can you identify why?
-- Works in PostgreSQL, fails in MySQL
SELECT customer_name
FROM customers
WHERE customer_name ~ '^[A-C]';
-- The ~ operator is PostgreSQL-specific regex matching!code>
Fix: Use LIKE 'A%' or REGEXP '^[A-C]' (MySQL syntax) for cross-database compatibility. Always verify your query against the target database’s dialect documentation.
12. Interview Questions
Q: Why did the relational model replace hierarchical databases?
A: Hierarchical databases required navigation-based access — programmers traversed pointers record by record. Queries depended on physical storage paths, so rearranging disk layout broke every query. The relational model separated logical structure from physical storage, enabling declarative queries that survive storage changes.
Q: What problem does Codd’s Rule 3 (Systematic Null Handling) solve?
A: Before systematic NULL handling, missing data was represented inconsistently — sometimes as zeros, sometimes as empty strings, sometimes as special sentinel values. This led to incorrect aggregations and comparisons. Codd mandated that the DBMS handle NULL as a systematic representation of "unknown" or "not applicable".
Q: How does SQL standardization benefit cross-platform compatibility?
A: The ANSI/ISO SQL standard defines a baseline syntax that all compliant databases must support. This means core queries (SELECT, INSERT, JOIN) work across PostgreSQL, MySQL, Oracle, and SQL Server — reducing vendor lock-in and enabling portable application code.
13. Production Considerations
- SQL dialect awareness: Maintain a dialect guide for your team. Document which features are ANSI-standard versus vendor-specific. Use database-agnostic syntax in application code when possible to reduce migration costs.
- Legacy system integration: When migrating from flat-file or hierarchical systems, map the old record structures to normalized relational tables. Use ETL pipelines to transform legacy data formats into SQL-compatible structures.
- Standards compliance monitoring: PostgreSQL leads in SQL standard compliance. Track which SQL:2016 and SQL:2023 features your database supports — JSON path queries, temporal tables, and row-pattern matching vary significantly across vendors.
- Version upgrade planning: Each PostgreSQL release adds features aligned with newer SQL standards. Plan upgrades to leverage new capabilities (e.g., MERGE in PostgreSQL 15, SQL/JSON in PostgreSQL 17).
Use Cases
Legacy system migration: Understanding flat-file and hierarchical data models helps when migrating old COBOL/IMS systems to modern relational databases
Database design justification: Knowing why relational models exist helps engineers defend schema design decisions during code reviews and architecture meetings
System design interviews: Explaining the trade-offs between relational and pre-relational models demonstrates deep foundational knowledge
Common Mistakes
Assuming SQL is the only query language: Many modern systems use query languages for graph databases (Cypher), document stores (MongoDB Query Language), and search engines (Elasticsearch DSL)
Ignoring SQL dialect differences: Writing queries that work in one database but fail in another because of vendor-specific syntax extensions
Believing Codd's 12 rules are strictly enforced: Most commercial databases satisfy only a subset of Codd's rules — the "relational" label is more pragmatic than absolute