Learning Objectives
By the end of this chapter, you will be able to:
- Distinguish database, DBMS, and database system.
- Group DBMS functions into language, governance, and survival stacks.
- Write DDL, DML, DCL, and TCL with a retail or hotel Members example.
- Map four roles to permissions.
- Price concurrency and backup on BS 2081 in NPR.
Database is the ledger, DBMS is the guard
In Butwal a mart and a lodge share one server. The database is the tables Members, Stock, and Bills. The DBMS is the software that creates and guards those tables. The database system adds hardware, apps, users, and procedures. Users touch forms, not tables. The DBMS decides if a write is allowed and keeps the ledger true.
flowchart LR
T[Counter and PMS form] --> DBMS[DBMS: MySQL or PostgreSQL]
M[Manager approval] --> DBMS
A[Auditor read only] --> DBMS
DBA[DBA] --> DBMS
DBMS --> DB[(Members, Stock, Bills)]
Framework 1: The language stack, DDL DML DCL TCL
A. DDL, build the house
Defines structure. Rare and powerful. Only DBA runs it.
CREATE TABLE Members (
MemberID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(60) NOT NULL,
Outlet VARCHAR(30),
Phone VARCHAR(15) UNIQUE
);
ALTER TABLE Members ADD loyalty_tier VARCHAR(20);
B. DML, live in the house
Reads and changes rows. Every cashier uses it through the app.
| Verb | Example |
|---|---|
| INSERT | INSERT INTO Members VALUES ('M-2144', 'Sita Sharma', 'Butwal', '9851000222'); |
| SELECT | SELECT Name FROM Members WHERE Outlet = 'Butwal'; |
| UPDATE | UPDATE Members SET Phone = '9851000222' WHERE MemberID = 'M-2144'; |
| DELETE | DELETE FROM Members WHERE MemberID = 'M-9999'; |
| GROUP BY | SELECT Outlet, SUM(Total) FROM Bills GROUP BY Outlet; |
C. DCL, who may do what
Grants and revokes. The gate.
GRANT SELECT, INSERT ON Members TO cashier_hari;
REVOKE DELETE ON Members FROM cashier_hari;
D. TCL, all or nothing
Groups work. COMMIT saves, ROLLBACK undoes. A transfer that debits stock at warehouse and credits sales at counter must be one transaction.
BEGIN;
UPDATE Stock SET Qty = Qty - 10 WHERE SKU = 'RICE25';
UPDATE Bills SET Total = Total + 42000 WHERE BillID = 'B301';
COMMIT;
| Stack | Verbs | Who runs | Risk if missing |
|---|---|---|---|
| DDL | CREATE, ALTER, DROP | DBA | Anyone reshapes ledger |
| DML | SELECT, INSERT, UPDATE, DELETE | Cashier via app | No daily work |
| DCL | GRANT, REVOKE | DBA | Clerk deletes history |
| TCL | COMMIT, ROLLBACK | App plus DBMS | Half transfer survives |
Framework 2: Governance and survival
A. Governance, truth before speed
- Integrity: primary key blocks duplicate MemberID, foreign key blocks bill without member, UNIQUE blocks duplicate phone, CHECK blocks negative quantity.
- Security: authentication proves who you are, authorization limits what you touch, audit logs record who changed what.
- Data dictionary: catalogue of tables, columns, keys, indexes. VAT field definition comes from it.
B. Survival, keep service up when two hands touch one bill
- Concurrency: locks serialize access. Stock of Rice 25kg is 120 bags on 2081-07-10. Counter A sells 10 bags, counter B sells 8 bags at same second. Without lock, stock lands at 110 or 112. With row lock, correct is 120 - 10 - 8 = 102 bags. Each complete sale is a transaction that either fully succeeds or is fully undone.
- Backup and recovery: full weekly, incremental nightly, restore tested monthly. A lodge cannot lose a weekend of bills to a power cut.
| Function | Control | Failure without |
|---|---|---|
| Integrity | Duplicate MemberID rejected | Two members share one ID |
| Security | Cashier cannot DELETE audit | History disappears before audit |
| Dictionary | Column list for VAT export | Wrong field exported |
| Concurrency | Row lock on SKU RICE25 | Lost update of 8 bags |
| Backup | Restore tested 2081-06-01 | Flood erases quarter |
Framework 3: People and products
- End users: cashiers post, receptionists check in, auditors read. No direct table access.
- Developers: build forms and VAT export that call SQL.
- Designers: choose tables and keys.
- DBA: owns structure, grants, backup, recovery. In a three outlet mart one owner plus vendor at Rs 5,000 a month.
| DBMS | Licence | Fit | Limit |
|---|---|---|---|
| MySQL | Open source | Default for retail and lodge | Needs tuning for analytics |
| PostgreSQL | Open source | Strong integrity | Fewer local vendors |
| SQL Server | Commercial | Windows shops | Core cost scales |
| Oracle | Commercial high | Core banking at large banks | Cost above shop need |
| MongoDB | Document | Catalogue beside ledger | Not an audit ledger |
| Access | Desktop | Single counter prototype | Fails beyond one LAN |
| Gain | Cost |
|---|---|
| One truth per member and per SKU | Server, UPS, DBA time |
| Role based access for VAT and stock | Design before entry |
| Repeatable VAT reports | Single failure if no backup |
| Integrity blocks errors at entry | Skill to test restore |
Nepal worked example: concurrency priced on BS 2081-07-10 (NPR)
A Butwal mart posts 420 bills a day. On 2081-07-10 SKU RICE25 stock at 120 bags receives two sales within one second: Counter A 10 bags and Counter B 8 bags. Without lock, clash leaves 110 or 112. With row lock for 80 ms, close is 102 and log shows cashier Hari at 14:01:22 and cashier Gita at 14:01:23.
Cost: server plus UPS Rs 18,000, backup disk Rs 12,000, rotation Rs 1,200 a month = Rs 14,400 a year, DBA Rs 60,000 a year. Year one = Rs 1,04,400. VAT on quarterly sales Rs 1,80,000. Output VAT = 1,80,000 x 0.13 = Rs 23,400. Sheet missed Rs 15,000 of sales, understated VAT = 15,000 x 0.13 = Rs 1,950. Query removes slippage. Two clashes a week at 8 bags missed is 16 bags x Rs 4,200 per bag = Rs 67,200 of stock error a week without locks. Locks remove that class entirely.
Self-check
Try this: build, permission, and VAT (calculable)
- Write GRANT that allows cashier_hari SELECT and INSERT on Members but not DELETE.
- Stock RICE25 at 120 bags with sales 10 and 8. Compute correct close and two wrong closes if one overwrites the other.
- Sales Rs 1,80,000 plus late Rs 15,000. Compute VAT at 13 percent for reported, corrected, and understated. State which function blocks duplicate MemberID and which blocks orphan bill.
Answer sketch
1. GRANT SELECT, INSERT ON Members TO cashier_hari; never grant DELETE. 2. Correct = 102. Wrong B overwrites A = 110. Wrong A overwrites B = 112. 3. Reported = 23,400. Corrected = 1,95,000 x 0.13 = 25,350. Understated = 1,950. Duplicate blocked by PRIMARY KEY, orphan by FOREIGN KEY.Summary
- Database is data, DBMS is guard, system adds hardware, apps, people, procedures.
- Languages group as build, use, gate, and all or nothing.
- Governance keeps truth, survival keeps service with locks and tested backup.
Next: business advantages, business intelligence, network basics.
Key Takeaways
- Name the language before the verb.
- Keys are integrity, GRANT is security, locks and COMMIT are concurrency.
- DBA is control, not overhead.
Discussion Questions
- Why must only DBA run DDL in a mart with three counters.
- Why is concurrency control important when two cashiers sell the same SKU at 14:01.
- What are three security features you expect in a DBMS for a lodge PMS.
Exercises
Short answer
- Define DBMS with one mart example and one hotel example.
- Differentiate DDL and DML with one verb each.
- What does TCL guarantee for a stock to bill transfer.
Long answer
- Group DBMS functions as language, governance, and survival. Use the 2081-07-10 stock clash to show lost update and lock fix at Rs 67,200 weekly exposure.
- Show VAT Rs 23,400 and understated Rs 1,950, plus backup at Rs 1,04,400 first year cost.


