Core CS · DBMS
Seven guarantees, four jobs, three users, one honest cost
Every advantage of a DBMS is one rule moved out of your code into one place nobody can skip. You will follow a single fee payment through those rules, meet the four jobs that put them there and the three kinds of user who live with them, and see the days when a plain file is the better answer.
01 The idea
Every advantage is a rule you stopped writing
The file-system problems in the previous lesson all came from the same source: the rules lived inside whichever program happened to be writing. Two programs meant two copies of the rule, and sooner or later one copy was out of date. A DBMS does not fix those problems one at a time. It fixes them once, by putting the rules underneath every program at the same moment.
That is why the advantages read like seven unrelated virtues and are really one move seen from seven angles. fee_paid >= 0 written as a CHECK constraint is integrity. The same constraint stops a careless import script producing a negative balance that contradicts the receipts, which is consistency. It is declared once in the schema instead of once per application, which is an enforced standard. And it holds for the clerk, the student portal and the nightly job at the same time, which is what sharing means. One line, four advantages, and no application code.
02 Worked example
One payment, five promises kept
Asha pays 12,000 rupees of her fee at the counter. A clerk opens the fees app and clicks Record payment. The app sends exactly one statement. Here is the table it lands on, and the statement itself.
CREATE TABLE student ( sid TEXT PRIMARY KEY, name TEXT NOT NULL, fee_paid NUMERIC(9,2) NOT NULL DEFAULT 0 CHECK (fee_paid >= 0));GRANT SELECT ON student TO clerk;GRANT UPDATE (fee_paid) ON student TO clerk;-- what the clerk's app sends when Asha pays 12000:UPDATE student SET fee_paid = fee_paid + 12000 WHERE sid = 'S1';
clerk on lines 7 and 8 is a database role, not a person. Every counter clerk logs in as a member of it, so the permission is written once and revoked once. Line 8 is column-level: the role may change fee_paid and nothing else on that table. Now follow the statement from the click to the disk.
The highlighted stop is the one students underrate. CHECK (fee_paid >= 0) is four words, and it fires for the clerk's app, for the accounts team's import script, for a developer who connects to production by accident, and for you at 2am in a terminal. Write the same rule in application code and you have written it for exactly one of those four.
Five stops, and the application supplied only the first one. Everything after it came from the schema and the server. Stop 2 is security. Stop 3 is integrity. Stop 4 is what makes backup and recovery possible at all, because a log entry written before the commit returns is what lets a restore replay the payment after a crash. Stop 5 is controlled redundancy, consistency and sharing at once, because there is only one copy to be consistent about. The seventh, enforced standards, is stop 1: NUMERIC(9,2) is what fee_paid means for the portal, the accounts export and the nightly job, and none of them gets a vote.
03 Mechanics
Who put each of those rules there
The five stops did not appear on their own. Somebody chose the column type, somebody wrote the GRANT, somebody decided the backup runs at 2am, and somebody clicked the button. Those are different jobs with different outputs, and an interviewer will ask you to tell them apart.
The four professional roles
| Role | The question they answer | What they hand over | The SQL they write |
|---|---|---|---|
| System analyst | What does the college need to record, and what should the screens do? | Requirements, and specifications for the canned transactions clerks will run all day | None. They write documents and talk to people. |
| Database designer | Which tables, columns, keys and constraints express that? | The schema and the ER diagram, including NUMERIC(9,2) and CHECK (fee_paid >= 0) | DDL: CREATE TABLE, ALTER TABLE |
| Application programmer | What statements does the app send, and where do the transactions begin and end? | The fees app, and the single UPDATE you traced in section 02 | DML: INSERT, UPDATE, DELETE, and SELECT, which many books count as DML and some split out as DQL. Plus the TCL around it: BEGIN, COMMIT, ROLLBACK |
| DBA | Who may connect, who may see what, and what happens when it breaks? | Roles and grants, the backup schedule and the restore drill, indexes, tuned settings | DCL: GRANT, REVOKE. Then admin work that is DDL or vendor tooling: CREATE INDEX, backups, restores |
And the three kinds of end user
| Kind of end user | How they reach the data | In this lesson | What they know about the schema |
|---|---|---|---|
| Naive, also called parametric | A screen someone else built, running the same few canned transactions all day with different parameters | The fees clerk clicking Record payment | Nothing. They do not know a table exists. |
| Sophisticated | Ad-hoc SQL or a reporting tool, writing their own queries | The finance officer totalling this term's collections | Enough to read a schema diagram and write a join. |
| Specialised | An application they build themselves, with data needs the plain relational toolkit was not designed for | The team building the campus map, storing shapes and asking “what is within 200 metres of this hostel?” | They know it well and often extend it. |
05 Cheat sheet
Seven advantages, and what each one costs
| Advantage | What it actually means | What it costs you |
|---|---|---|
| Controlled redundancy | One fact lives in one place. Copies exist only where you deliberately put them, such as an index or a replica, and the database maintains those. | A read that once touched one file now joins several tables. |
| Consistency | If a fact is stored once, no two readers can be told different things about it. | You give up the freedom to let one app keep its own slightly different version. |
| Sharing | Many users write at the same time, and the database, not your code, decides the order. | Locks and waits. A blocked transaction is the price of not losing one. |
| Enforced standards | Names, types and formats are declared once in the schema and every client obeys them. | Changing a column is a migration, coordinated across every app that reads it. |
| Integrity | CHECK, NOT NULL and foreign keys are tested on every write from every client. | Every insert and update pays for the check before the row lands. |
| Security | GRANT and REVOKE per user, per table, per column. Views hand out a slice and hide the rest. | Somebody has to own and review those grants, and that somebody is a job. |
| Backup and recovery | A committed transaction survives a crash, and with log archiving switched on you can restore to a chosen moment. | Disk for logs and backups, and a restore drill that has to be rehearsed to be real. |
06 Where & why
Where the guarantees pay, and where they are pure cost
A DBMS is a trade, not a virtue. You pay latency on every write, a schema you have to migrate, and a person to look after it. You get rules that hold no matter who writes. When there is one writer and nothing worth enforcing, you are paying all of that and getting nothing back.
A college fee system, a bank ledger, an ERP. Several apps and several people write the same rows all day, and a wrong number is a real loss. Every advantage in the cheat sheet is being used here, including the ones you never see fire.
SQLite runs inside Android, iOS and the major browsers, storing settings and history in one file, in your own process. Transactions, constraints and SQL, with nothing to install and nobody to page at 2am. When someone says a database is too heavy for a small app, this is the answer: the weight was the server, not the guarantees.
A file one analyst opens, filters and never writes back is the case where none of this earns its keep. One writer, so no payment can be overwritten. No second app, so no standard to enforce. Loading it into Postgres to run one GROUP BY costs more than it saves.
Session tokens, rate-limit counters, a leaderboard rebuilt from the real tables every hour. Losing all of it costs a re-login and a recompute. Redis, on its default settings, persists with a periodic snapshot rather than a flush per commit, and neither store offers you a foreign key. On derived data, that is the trade you want.
07 Interview questions
What they actually ask
This topic is the opening question in a huge share of DBMS interviews, and the one most often answered as a memorised list. The candidates who stand out name the mechanism behind each advantage and are willing to say when they would not use a database at all.
What does a DBMS actually give you that a folder of files does not?
List the advantages of a DBMS.
Consistency and integrity sound like the same thing. What is the difference?
What does a DBA actually do all day?
Naive, sophisticated, specialised: what separates the three kinds of end user?
Where does the application programmer end and the DBA begin?
Two people update the same row at the same moment. What stops one update from being lost?
Is backup and recovery really a DBMS advantage, or does that belong to the ops team?
What is the real cost of using a DBMS?
When would you tell an interviewer not to use a DBMS at all?
08 Practice problems
Six that test judgement, not recall
Every one of these is answerable from this lesson alone. For each, say what the workload is before you say what the answer is: how many writers, what a wrong row costs, and who else reads it.