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 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 cooperative keeps data on a server. The database is the tables Members, Accounts, and Transactions. 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[Teller form and IRD export] --> DBMS[DBMS: MySQL or Oracle]
M[Manager approval] --> DBMS
A[Auditor read only] --> DBMS
DBA[DBA] --> DBMS
DBMS --> DB[(Members, Accounts, Transactions)]
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 INT PRIMARY KEY,
Name VARCHAR(60) NOT NULL,
Branch VARCHAR(30),
Phone VARCHAR(15) UNIQUE
);
ALTER TABLE Members ADD citizenship_no VARCHAR(20);
B. DML, live in the house
Reads and changes rows. Every teller uses it through the app.
| Verb | Example |
|---|---|
| INSERT | INSERT INTO Members VALUES (9841, 'Sita Sharma', 'Butwal', '9851000222'); |
| SELECT | SELECT Name FROM Members WHERE Branch = 'Butwal'; |
| UPDATE | UPDATE Members SET Phone = '9851000222' WHERE MemberID = 9841; |
| DELETE | DELETE FROM Members WHERE MemberID = 9999; |
| GROUP BY | SELECT Branch, SUM(Interest) FROM Transactions GROUP BY Branch; |
C. DCL, who may do what
Grants and revokes. The gate.
GRANT SELECT, INSERT ON Members TO teller_hari;
REVOKE DELETE ON Members FROM teller_hari;
D. TCL, all or nothing
Groups work. COMMIT saves, ROLLBACK undoes. A transfer that debits one account and credits another must be one transaction.
BEGIN;
UPDATE Accounts SET Balance = Balance - 50000 WHERE AccountID = 'A101';
UPDATE Accounts SET Balance = Balance + 50000 WHERE AccountID = 'A102';
COMMIT;
| Stack | Verbs | Who runs | Risk if missing |
|---|---|---|---|
| DDL | CREATE, ALTER, DROP | DBA | Anyone reshapes ledger |
| DML | SELECT, INSERT, UPDATE, DELETE | Teller 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 loan without member, UNIQUE blocks duplicate phone, CHECK blocks negative balance.
- 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. IRD field definition comes from it.
B. Survival, keep service up when two hands touch one balance
- Concurrency: locks serialize access. Balance Rs 2,00,000 on 2081-07-10. A deposits Rs 50,000, B withdraws Rs 20,000 at same second. Without lock, balance lands at Rs 2,50,000 or Rs 1,80,000. With row lock, correct is 2,00,000 + 50,000 - 20,000 = Rs 2,30,000.
- Backup and recovery: full weekly, incremental nightly, restore tested monthly.
| Function | Control | Failure without |
|---|---|---|
| Integrity | Duplicate MemberID rejected | Two members share one ID |
| Security | Teller cannot DELETE audit | History disappears before NRB |
| Dictionary | Column list for IRD export | Wrong field exported |
| Concurrency | Row lock on A101 | Lost update Rs 30,000 |
| Backup | Restore tested 2081-06-01 | Flood erases quarter |
Framework 3: People and products
- End users: tellers post, members view, auditors read. No direct table access.
- Developers: build forms and IRD export that call SQL.
- Designers: choose tables and keys.
- DBA: owns structure, grants, backup, recovery. In Siddhartha one staff plus vendor at Rs 5,000 a month.
| DBMS | Licence | Fit | Limit |
|---|---|---|---|
| MySQL | Open source | Default for SME | 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 cooperative need |
| MongoDB | Document | Catalogue beside ledger | Not an audit ledger |
| Access | Desktop | Single user prototype | Fails beyond one LAN |
| Gain | Cost |
|---|---|
| One truth per member | Server, UPS, DBA time |
| Role based access for IRD and NRB | 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)
Siddhartha posts 420 transactions a day. On 2081-07-10 Account A101 at Rs 2,00,000 receives Rs 50,000 deposit and Rs 20,000 withdrawal within one second. Without lock, error Rs 20,000 to Rs 30,000 per clash. At two clashes a week, quarterly risk about Rs 2,40,000. With lock, close is Rs 2,30,000 and log shows Hari at 14:01:22 and Gita at 14:01:23.
Cost: VPS plus install 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. IRD quarter fees Rs 1,80,000. Output VAT = 1,80,000 x 0.13 = Rs 23,400. Sheet missed Rs 15,000, understated VAT = 15,000 x 0.13 = Rs 1,950. Query removes slippage.
Self-check
Try this: build, permission, and VAT (calculable)
- Write GRANT that allows teller_hari SELECT and INSERT on Members but not DELETE.
- Account A101 Rs 2,00,000 with Rs 50,000 deposit and Rs 20,000 withdrawal. Compute correct close and two wrong closes if one overwrites the other.
- Fees 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 deposit.
Answer sketch
1. GRANT SELECT, INSERT ON Members TO teller_hari; never grant DELETE. 2. Correct = 2,30,000. Wrong B overwrites A = 1,80,000. Wrong A overwrites B = 2,50,000. 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.
Key Takeaways
- Name the language before the verb.
- Keys are integrity, GRANT is security, locks and COMMIT are concurrency.
- DBA is control, not overhead.
Exercises
Short answer
- Distinguish database, DBMS, and system with Butwal example.
- Differentiate DDL and DML with one verb each.
- What does TCL guarantee for a transfer?
Long answer
- Group DBMS functions as language, governance, and survival. Use 2081-07-10 clash to show lost update and lock fix.
- Show IRD VAT Rs 23,400 and understated Rs 1,950, plus backup at Rs 1,04,400.


