Database Management SystemUnit 113 min read
Database Systems: Data, DBMS, Users, Models & 3-Schema Architecture
Unit 1 of Database Management System introduces core concepts like data hierarchy, DBMS architecture, user types, data models, and the ANSI/SPARC 3-schema framework—essential for designing scalable databases and understanding real-world implementations like eSewa or Ncell systems.
TAKEAWAYS:
- Understand the data hierarchy (bits → fields → records → files → databases) and how it maps to real tables like
Customerin Ncell’s billing system. - Learn the three types of database users (naive, sophisticated, and stand-alone) and their roles in apps like Daraz’s inventory vs. customer-facing interfaces.
- Master the three data models (hierarchical, network, relational) and why relational dominates today (e.g., MySQL in banks).
- Visualize the ANSI/SPARC 3-schema architecture (external → conceptual → internal) using the example of NEPSE’s stock data layers.
- Compare file-based systems vs. DBMS using a table, highlighting why DBMS wins in concurrency and integrity (e.g., Kathmandu traffic route updates).
- Know five key DBMS functions (data definition, manipulation, control, security, recovery) and how they apply to eSewa’s transaction logs.
1. What is Data? The Building Blocks of a Database
Data is the raw facts stored in a computer system, organized to be useful. It comes in layers:
graph TD
A["Bits (0/1)"] --> B["Bytes (8 bits)"]
B --> C["Fields/Attributes\n(e.g., SID, SName)"]
C --> D["Records/Tuples\n(e.g., {101, 'Ramesh'})"]
D --> E["Files/Relations\n(e.g., Student table)"]
E --> F["Database\n(e.g., University_DB)"]Example in Nepal:
- Ncell’s database stores records like
{CustomerID: 12345, Name: 'Ram', Phone: 9800000000, Balance: 500}as a file/table in its relational DBMS. - eSewa uses fields like
TransactionID,Amount,Statusto track payments.
2. Database vs. File-Based Systems: Why DBMS Wins
| Feature | File-Based System | Database Management System (DBMS) |
|---|---|---|
| Data Sharing | Limited (one user at a time) | Multi-user access (e.g., 1000+ users in NEPSE) |
| Data Integrity | Manual checks (error-prone) | Constraints (e.g., NOT NULL, UNIQUE) |
| Concurrency | Locks files (slow) | Row-level locking (e.g., Daraz order processing) |
| Backup/Recovery | Manual (risky) | Automated (e.g., NTC’s network logs) |
| Security | Passwords on files | Role-based access (e.g., admin vs. cashier in banks) |
Real-World Tie-In:
- Kathmandu Traffic Police used to track violations in Excel files (single-user, no backups). Now, they use a DBMS to log fines, vehicles, and violations in real time—reducing errors by 90%.
- Pathao’s ride-hailing system relies on a DBMS to:
- Store driver locations (spatial data).
- Match riders to drivers (concurrency control).
- Process payments (transaction integrity).
3. Database Users: Who Interacts with the System?
Three types of users access a DBMS, each with different needs:
Examples in Nepal:
- Naive User: A Khalti app user who checks their balance (
SELECT balance FROM Account WHERE user_id = 123;). - Sophisticated User: A NEPSE analyst running queries like:
SELECT stock_symbol, AVG(price) FROM Trades WHERE trade_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY stock_symbol; - Stand-Alone User: A local grocery shop using Excel to track inventory (no DBMS).
4. Data Models: How Data is Structured
Three classic models explain how data is organized. Relational dominates today:
| Model | Structure | Example Use Case | Weakness |
|---|---|---|---|
| Hierarchical | Tree-like (parent-child) | Old IBM mainframes | Rigid, hard to update |
| Network | Graph (many-to-many) | Airlines reservation systems (1970s) | Complex queries |
| Relational | Tables (rows/columns) | 90% of modern systems (MySQL, PostgreSQL) | Joins can be slow for big data |
Visual: Relational Model
erDiagram
STUDENT ||--o{ STUDIES : "takes"
STUDIES }|--|| COURSE : "enrolled_in"
STUDENT {
string SID PK "Student ID"
string SName "Full Name"
string SAddress "Address"
}
COURSE {
string CID PK "Course ID"
string CName "Course Name"
int Credit_hours "Credits"
}
STUDIES {
string SID PK,FK
string CID PK,FK
int Semester
}Relational model with STUDIES junction table (many-to-many) Why Relational Wins:
- eSewa uses relational tables for:
Users(user_id, name, email)Transactions(tx_id, user_id, amount, status)Accounts(account_id, user_id, balance)
- Ncell stores:
Customers(cid, name, phone)Calls(call_id, cid, duration, timestamp)
5. ANSI/SPARC 3-Schema Architecture: The Database "OS"
Databases are designed in three layers, like an operating system:
graph TD
A["External Schema\n(User views)\n(e.g., Student portal sees only grades)"] --> B["Conceptual Schema\n(Logical design)\n(e.g., ER diagram of University_DB)"]
B --> C["Internal Schema\n(Physical storage)\n(e.g., Indexes, file locations)"]
A -->|"Mapped via"| D["External Schema\nto Conceptual Schema"]
B -->|"Mapped via"| E["Conceptual Schema\nto Internal Schema"]
C -->|"Implemented by"| F["DBMS\n(MySQL, Oracle)"]Example: NEPSE’s Stock Database
- External Schema:
- Trader view: Only sees
stock_symbol,price,volume. - Admin view: Sees
Trades,Users,Brokerages.
- Trader view: Only sees
- Conceptual Schema:
- ER diagram with entities:
Trader,Stock,Trade,Brokerage.
- ER diagram with entities:
- Internal Schema:
- Tables stored on SSDs with indexes on
trade_idandstock_symbol.
- Tables stored on SSDs with indexes on
Why This Matters:
- Daraz uses this to:
- Show customers only product details (external).
- Hide inventory and supplier data (conceptual).
- Optimize storage (internal, e.g., sharding by region).
6. Database Languages: SQL and DDL/DML/DCL
Databases use three types of languages:
| Language Type | Purpose | Example Commands | Used by Whom? |
|---|---|---|---|
| DDL | Define structure | CREATE TABLE, ALTER TABLE |
DBAs (e.g., setting up Ncell’s Customers table) |
| DML | Manipulate data | SELECT, INSERT, UPDATE, DELETE |
Users (e.g., eSewa transferring money) |
| DCL | Control access | GRANT, REVOKE |
Admins (e.g., NEPSE restricting data) |
Worked Example: NTC’s Network Logs
-- DDL: Create a table for network alerts
CREATE TABLE NetworkAlerts (
alert_id INT PRIMARY KEY,
device_id VARCHAR(50),
alert_type VARCHAR(50),
timestamp DATETIME,
status VARCHAR(20)
);
-- DML: Insert a new alert (e.g., fibre cut in Kathmandu)
INSERT INTO NetworkAlerts (alert_id, device_id, alert_type, timestamp, status)
VALUES (101, 'FIBER-KTM-01', 'Link Down', '2023-10-15 14:30:00', 'Open');
-- DCL: Grant a technician access to view alerts
GRANT SELECT ON NetworkAlerts TO 'tech_kathmandu';
7. DBMS Functions: What a DBMS Actually Does
A DBMS performs five core functions, visualized below:
mindmap
root((DBMS Functions))
Data Definition
CREATE, ALTER, DROP
Data Manipulation
SELECT, INSERT, UPDATE, DELETE
Data Control
Concurrency, Recovery
Security
Authentication, Authorization
Integrity
Constraints, TriggersReal-World Application: Bank Loans
- Data Definition: Define
Loantable withloan_id,customer_id,amount,interest_rate. - Data Manipulation: Calculate monthly payments:
SELECT customer_id, amount, (amount * interest_rate / 100) AS monthly_payment FROM Loans WHERE status = 'Approved'; - Data Control: Ensure only one user updates a loan at a time (concurrency).
- Security: Only loan officers can
UPDATEthestatusfield. - Integrity: Enforce
CHECK (interest_rate BETWEEN 5 AND 15).
8. Database Recovery: Handling Crashes
Databases use three methods to recover from failures:
| Method | How It Works | Example |
|---|---|---|
| Backup and Restore | Full copy of DB at intervals | Ncell backs up call records nightly |
| Transaction Logs | Records every change (undo/redo) | eSewa logs every transaction for rollback |
| Shadow Paging | Keeps old and new pages until commit | Used in high-frequency systems like NEPSE |
Example: Daraz Order Processing
- User places order → DBMS writes to transaction log.
- System crashes → On restart, DBMS replays logs to recover unsaved orders.
- Partial update (e.g., inventory deducted but payment failed) → Rollback cancels the order.
In the Real World
eSewa’s Transaction System
- Idea Used: Relational model + 3-schema architecture
- How: Stores
Users,Transactions, andAccountsas separate tables. The external schema shows users only their transactions, while the conceptual schema links all tables viauser_id. The internal schema optimizes storage (e.g., indexes ontx_id).
Ncell’s Billing Database
- Idea Used: Data hierarchy + DBMS functions
- How:
- Bits → Bytes: Phone numbers stored as
VARCHAR(15). - Fields → Records: Each call is a record in the
Callstable. - DBMS Functions: Uses DML to calculate bills (
SELECT SUM(duration) FROM Calls WHERE user_id = 123;), DCL to restrict access (GRANT SELECT ON Bills TO 'customer_123'), and recovery to handle power outages.
- Bits → Bytes: Phone numbers stored as
NEPSE’s Stock Trading Platform
- Idea Used: 3-schema architecture + concurrency control
- How:
- External Schema: Traders see only
stock_symbol,price,volume. - Conceptual Schema: Links
Traders,Stocks, andTradesviatrade_id. - Concurrency: Ensures two traders can’t buy the same share simultaneously (row-level locking).
- External Schema: Traders see only
Exam Tip
- Diagrams Are Worth Marks:
- Always draw the 3-schema architecture or an ER diagram for questions on design.
- Example: For a hospital DB, show:
- External: Doctor sees only
PatientsandPrescriptions. - Conceptual: Entities
Doctor,Patient,Appointmentwith relationships. - Internal: Tables stored with indexes on
patient_id.
- External: Doctor sees only
SQL Queries = Easy Marks:
- Practice INSERT, SELECT, and JOIN questions. For example:
Given tables
Account(ac_no, balance)andCustomer(cid, name), write SQL to insert a new customer and link their account.INSERT INTO Customer VALUES (101, 'Ram', 'Kathmandu'); INSERT INTO Account VALUES ('ACC101', 5000);
- Practice INSERT, SELECT, and JOIN questions. For example:
Compare File-Based vs. DBMS:
- Exams often ask: "Why use a DBMS instead of Excel?"
- Answer: Use a comparison table (as above) and mention concurrency, integrity, and recovery.
Real-World Examples:
- Tie answers to Nepali systems (e.g., "Like eSewa’s transaction logs, a DBMS uses transaction logs for recovery").
- Avoid generic answers like "used in banking"—specify how (e.g., "relational model for accounts").
Constraints and Normalization:
- Even though this is Unit 1, exams sometimes ask:
"Define four database constraints with examples."
- Answer:
- Primary Key:
SIDinStudenttable (unique identifier). - Foreign Key:
SIDinEnrollmenttable (links toStudent). - NOT NULL:
EmailinCustomertable (cannot be empty). - CHECK:
Age > 18forVotertable.
- Primary Key:
- Answer:
- Even though this is Unit 1, exams sometimes ask:
Based on the TU BBA syllabus for Database Management System (IT232), unit 1.
Discussion
Loading…