Learning Objectives
By the end of this chapter, you will be able to:
- Define a database model and state what it fixes before any table is built.
- Group legacy models as tree and graph and state where each breaks.
- Explain the relational core with tables, keys, and SQL.
- Group modern models as object and NoSQL families and match each to a BBA use.
- Choose a model for a cooperative that must report to IRD, with cost in NPR dated BS 2081.
One cooperative, three ways to store the same member
Siddhartha Saving Cooperative in Rupandehi has 4,800 members. On 2081-06-15 the manager asks: list members with a recurring deposit and a loan in the same branch. One staff searches sheets that act like a tree. One follows pointers in an old graph. One runs a JOIN. Only the tables answer in one query. The question is not hard. The model makes it hard or easy. A database model sets how data is shaped, how records link, and how queries travel.
flowchart TB
Q[Question: members with deposit and loan] --> H[Tree: walk from root]
Q --> N[Graph: follow pointers]
Q --> R[Tables: JOIN on MemberID]
Framework 1: Legacy geometry, tree and graph
Group these because both use pointers. The split is how many parents a child may have.
A. Hierarchical, one parent per child
Data sits in a tree. IBM IMS used this for banks in the 1960s.
- Shape: parent to child, one to many only.
- Navigation: start at root, walk down.
- Fit: one to many that never changes, such as company to department.
- Break: many to many requires duplication.
For a cooperative: Branch as root, Members under Branch, Deposits under Member. Fast for deposits of one member. Slow for members across branches with the same product.
B. Network, many parents per child
Network extends the tree and lets a child have many parents through pointers. A member can link to several loans at once. The shape is a graph. Fit improves for many to many. Cost is complexity and heavy schema change.
| Model | Structure | Cap | Query | Lesson |
|---|---|---|---|---|
| Hierarchical | Tree, single parent | One to many | Walk from root | Single branch look up |
| Network | Graph, many parents | Many to many via pointers | Follow links | Shared parts logic now retired |
Both bury logic in navigation. Change the question, change the code.
Framework 2: Relational core, tables that stand alone
E. F. Codd proposed this in 1970. One entity per table. Rows are instances. Columns are attributes. Rules live in keys, not in paths.
- Primary key: identifies one row only. MemberID 9841 appears once in Members.
- Foreign key: repeats that value elsewhere to point back. MemberID 9841 in Deposits and Loans points to Members.
- Relationships: one to one such as member to PAN, one to many such as member to deposits, many to many through a link table such as Enrollments.
Tables for Siddhartha on 2081-06-15:
Members
| MemberID (PK) | Name | Branch | Phone |
|---|---|---|---|
| 9841 | Sita Sharma | Butwal | 9851000222 |
| 9842 | Ram Thapa | Butwal | 9851000333 |
Deposits
| DepositID (PK) | MemberID (FK) | Product | Balance NPR |
|---|---|---|---|
| D101 | 9841 | Recurring | 85,000 |
| D102 | 9841 | Fixed | 120,000 |
Loans
| LoanID (PK) | MemberID (FK) | Product | Principal NPR |
|---|---|---|---|
| L201 | 9841 | Micro | 150,000 |
| L202 | 9842 | Micro | 90,000 |
One query answers the manager without walking a tree:
SELECT m.MemberID, m.Name
FROM Members m
JOIN Deposits d ON m.MemberID = d.MemberID AND d.Product = 'Recurring'
JOIN Loans l ON m.MemberID = l.MemberID
WHERE m.Branch = 'Butwal';
Result is 9841 Sita Sharma. The same schema supports the IRD ask: sum interest by branch.
SELECT Branch, SUM(Interest) FROM Transactions
WHERE TxnDate BETWEEN '2081-04-01' AND '2081-06-15'
GROUP BY Branch;
Relational wins because tables are predictable, SQL is declarative, and integrity blocks duplicates.
Framework 3: Flexible geometry, object and NoSQL
Group these because they relax the table shape for scale or variety.
- Object: attributes plus behaviour. Fits drawings.
- Document: JSON rows with varied fields. MongoDB. Fits catalogues where one item has colour and another has expiry.
- Key value: Redis. Fits wallet session tokens.
- Column family: Cassandra. Fits high write logs.
- Graph: Neo4j. Fits fraud rings where the edge is the question.
Core ledger stays relational for NRB and IRD. Flexible stores sit at the edge.
Nepal worked example: tree cost versus table cost on BS 2081-06-15 (NPR)
Taxable service fees for the quarter are Rs 2,40,000. A clerk keeps each branch as a subtree in sheets. Adding citizenship_no for IRD needs vendor redesign at Rs 45,000. The relational change is one DDL: ALTER TABLE Members ADD citizenship_no VARCHAR(20). Cost is DBA 2 hours at Rs 1,500 per hour = Rs 3,000 plus testing Rs 1,200 = Rs 4,200. Saving = 45,000 - 4,200 = Rs 40,800.
VAT proof: output at 13 percent on Rs 2,40,000 = 2,40,000 x 0.13 = Rs 31,200. Branch split from one GROUP BY is Butwal Rs 18,200 and Sunwal Rs 13,000. The sheet total missed a late Rs 22,000 line, so understated VAT = 22,000 x 0.13 = Rs 2,860. One table removes that risk.
Self-check
Try this: keys and VAT (calculable)
Members 4,800 rows, Deposits 6,200, Loans 2,100 on 2081-06-15.
- In Members which column is primary key and why can phone not serve?
- In Deposits and Loans which column is foreign key and where does it point?
- JOIN Deposits to Members on MemberID, one to many. Maximum result rows before filter equals rows in which table and why?
- IRD output VAT on Rs 18,00,000 at 13 percent is what? Incremental VAT if Rs 2,20,000 was late?
Answer sketch
1. MemberID. Phone can change and duplicate, so it cannot guarantee identity. 2. MemberID in both tables, points to Members.MemberID. 3. Deposits at 6,200. Bounded by the many side, each deposit matches at most one member. 4. VAT = 18,00,000 x 0.13 = NPR 2,34,000. Incremental = 2,20,000 x 0.13 = NPR 28,600. Corrected = 2,62,600.Summary
- Tree forces root walks, graph adds pointers, both hide logic in paths.
- Relational uses keys and SQL. One Member row supports many deposits and loans.
- Modern stores add flexibility beside the ledger. Schema change costs Rs 4,200 versus Rs 45,000 and VAT Rs 31,200 removes Rs 2,860 gap.
Key Takeaways
- Name the model by how records link.
- Primary key fixes identity, foreign key fixes belonging.
- NoSQL is not one model. Document, key value, column family, and graph differ.
Exercises
Short answer
- Define a database model and name two legacy and two modern families.
- Differentiate primary key and foreign key with 9841 Sita Sharma.
Long answer
- Compare hierarchical, network, and relational on structure and query. Use 4,800 members to show why JOIN beats tree walk and how VAT Rs 31,200 repeatably splits by branch.


