Why Databases Exist: What Goes Wrong Without One
Quick answer Keeping everything in one wide table repeats the same facts over and over, and a half-finished update then leaves one member stored with two different cities — the exact mess a DBMS is built to prevent.
A school office once ran entirely on registers: one for admissions, one for library issues, one for fees. The same student's name and city were copied by hand into all three. That is the file-based approach, and computerising it without a database only makes the copying faster, not safer.
Let us build that mess for real and watch it break. Everything below was run on MySQL 8.0.41.
CREATE DATABASE cs12_database_concepts;
USE cs12_database_concepts;
CREATE TABLE LIBRARY_FLAT (
MemberId CHAR(4),
MemberName VARCHAR(25),
MemberCity VARCHAR(20),
BookCode CHAR(5),
BookTitle VARCHAR(30),
IssueDate DATE
);
INSERT INTO LIBRARY_FLAT VALUES
('M01','Aarav Sharma','Delhi','B101','Wings of Fire','2026-07-02'),
('M01','Aarav Sharma','Delhi','B107','Train to Pakistan','2026-07-14'),
('M02','Diya Nair','Kochi','B101','Wings of Fire','2026-07-05'),
('M02','Diya Nair','Kochi','B120','The God of Small Things','2026-07-19'),
('M03','Rohan Verma','Jaipur','B107','Train to Pakistan','2026-07-21');
SELECT * FROM LIBRARY_FLAT;The output MySQL returned:
+----------+--------------+------------+----------+-------------------------+------------+
| MemberId | MemberName | MemberCity | BookCode | BookTitle | IssueDate |
+----------+--------------+------------+----------+-------------------------+------------+
| M01 | Aarav Sharma | Delhi | B101 | Wings of Fire | 2026-07-02 |
| M01 | Aarav Sharma | Delhi | B107 | Train to Pakistan | 2026-07-14 |
| M02 | Diya Nair | Kochi | B101 | Wings of Fire | 2026-07-05 |
| M02 | Diya Nair | Kochi | B120 | The God of Small Things | 2026-07-19 |
| M03 | Rohan Verma | Jaipur | B107 | Train to Pakistan | 2026-07-21 |
+----------+--------------+------------+----------+-------------------------+------------+Something is already wrong. Data redundancy: the pair Aarav Sharma / Delhi is stored twice, and the title Wings of Fire is stored twice, only because two loans happened. Wasted space is the least of it. Redundancy is what makes the next three problems possible.
Update anomaly. Diya Nair shifts from Kochi to Thrissur. A clerk updates the row in front of him and moves on:
UPDATE LIBRARY_FLAT SET MemberCity='Thrissur'
WHERE MemberId='M02' AND BookCode='B101';
SELECT MemberId, MemberName, MemberCity FROM LIBRARY_FLAT WHERE MemberId='M02';+----------+------------+------------+
| MemberId | MemberName | MemberCity |
+----------+------------+------------+
| M02 | Diya Nair | Thrissur |
| M02 | Diya Nair | Kochi |
+----------+------------+------------+One member, two cities, and nothing in the system says which is correct. This is data inconsistency. Notice that MySQL did not complain — a flat table has no way of knowing those two rows were supposed to agree. An audit query makes the damage countable:
SELECT MemberId, COUNT(DISTINCT MemberCity) AS CitiesOnRecord
FROM LIBRARY_FLAT
GROUP BY MemberId;+----------+----------------+
| MemberId | CitiesOnRecord |
+----------+----------------+
| M01 | 1 |
| M02 | 2 |
| M03 | 1 |
+----------+----------------+Deletion anomaly. Rohan Verma returns his only book, so the loan record is deleted:
DELETE FROM LIBRARY_FLAT WHERE MemberId='M03' AND BookCode='B107';
SELECT COUNT(*) AS RowsForM03 FROM LIBRARY_FLAT WHERE MemberId='M03';+------------+
| RowsForM03 |
+------------+
| 0 |
+------------+Rohan Verma has vanished from the library's records altogether. He is still a member; we deleted a loan and lost a person, because there was nowhere else to keep the fact that he exists.
Insertion anomaly. A new member enrols today but has not borrowed anything yet. There is no row we can create for him without leaving BookCode, BookTitle and IssueDate empty. We cannot record a member independently of a loan.
Those four problems are the whole justification for a database. A database is an organised collection of related data. A DBMS (Database Management System) is the software that stores that data, enforces rules on it and answers queries about it. MySQL is a DBMS. A DBMS that keeps its data as relations and links them through common attributes — the model this chapter is about — is called an RDBMS, a Relational DBMS; MySQL, Oracle, PostgreSQL and SQLite are all RDBMS products.
What a DBMS gives you that loose files cannot:
- Controlled redundancy — each fact is stored once, in the table where it belongs.
- Consistency — because a fact is stored once, it cannot disagree with itself.
- Data integrity — rules such as marks lie between 0 and 100, or this hostel code must exist, are enforced by the software rather than by a clerk's memory.
- Sharing with concurrency control — many users read and write at the same time without corrupting each other's work.
- Security — different users get different privileges on different tables.
- Backup and recovery — the DBMS can restore a consistent state after a crash.
- Data independence — how data is physically stored can change without rewriting every program that uses it.
The cure for all four anomalies is the same: store each fact once, in a relation of its own, and link the relations together. Member details in one table, loan details in another, joined by MemberId. How those relations are described, and what keeps the link honest, is the rest of this chapter.
- The file-based approach fails through data redundancy, which then causes update, deletion and insertion anomalies.
- Redundancy plus a partial update produces inconsistency with no warning from the system — we saw one member stored with two different cities at once.
- A deletion anomaly destroys facts you never meant to delete: removing Rohan Verma's only loan removed every trace of him as a member.
- A database stores each fact once; a DBMS is the software that enforces the rules on it, and a DBMS built on the relational model is called an RDBMS.
- Key benefits of a DBMS: controlled redundancy, consistency, integrity, sharing, security, backup and recovery, and data independence.
