Database Management SystemUnit 28 min read
Data Models, Schemas, Instances: Foundations of Database Design
Unit 2 of Database Management System: Explores how databases organize data through data models (hierarchical, network, relational, object-oriented), schemas (logical/physical), and instances (actual data snapshots), with a focus on relational schemas, functional dependencies, and quality measures like normalization.
1. Introduction: What is a Data Model?
A data model is a structured representation of data, its relationships, and constraints. It defines how data is organized, stored, and accessed in a database. Think of it as the "blueprint" for a database system.
Key Types of Data Models
mindmap
root((Data Models))
Hierarchical
Tree-like structure
Example: Old mainframe systems
Network
Many-to-many relationships
Example: Early IBM databases
Relational
Tables (relations), rows (tuples), columns (attributes)
Example: Modern SQL databases
Object-Oriented
Objects with methods + attributes
Example: ObjectDB, MongoDB (NoSQL)
XML/JSON
Semi-structured, nested data
Example: APIs (e.g., Daraz product listings)Why Relational Models Dominate
- Simplicity: Tables are intuitive for most users.
- Flexibility: Supports complex queries (e.g., "Find students enrolled in >3 courses").
- Scalability: Used by banks (NMB, Standard Chartered), e-commerce (Daraz), and telecom (NTC).
2. Schemas and Instances: The Static vs. Dynamic View
Definitions
- Schema: The structure of the database (e.g., table names, columns, data types).
Example:
Student(SID INT, SName VARCHAR(50), City VARCHAR(30)). - Instance: A snapshot of data at a point in time (e.g., all students enrolled in 2024).
- Metadata: Data about data (e.g., "SID is a primary key").
Example: University Database
erDiagram
Student ||--o{ Enrollment : takes
Enrollment ||--o{ Course : enrolls_in
Student {
int SID PK
string SName
string City
}
Course {
int CID PK
string CName
int Credits
}
Enrollment {
int SID FK
int CID FK
char Grade
}Instance (2024 data):
| SID | SName | City |
|---|---|---|
| 101 | Ramesh | Kathmandu |
| 102 | Priya | Pokhara |
3. Functional Dependencies (FD) and Quality Measures
Functional Dependency (FD)
- An attribute determines another (e.g.,
SID → SName). - Notation:
X → YmeansXfunctionally determinesY.
Worked Example: Enrollment Table
| SID | CID | Grade |
|---|---|---|
| 101 | 201 | A |
| 101 | 202 | B |
| 102 | 201 | A |
FDs:
SID → Grade(each student has one grade per course).CID → CName(course ID uniquely identifies the course name).
Four Informal Quality Measures
| Measure | Description | Example Violation |
|---|---|---|
| Atomicity | Each attribute holds a single value. | Address storing "Kathmandu, Nepal" (should split). |
| No Redundancy | No duplicate data. | Storing SName twice in Student table. |
| No Update Anomaly | Changing one value doesn’t break others. | Updating City for one student affects another. |
| No Insert/Delete | Can add/delete records without losing data. | Can’t enroll a student in zero courses. |
4. Relational Data Model vs. Flat Files
| Feature | Relational Model | Flat File (e.g., CSV) |
|---|---|---|
| Structure | Tables with relationships. | Single file, no inherent links. |
| Querying | SQL (structured queries). | Manual parsing (e.g., Python scripts). |
| Scalability | Handles millions of records. | Struggles with joins/large datasets. |
| Example Use | NEPSE stock data (relational). | Excel sheets (flat). |
5. Three-Schema Architecture: Isolation Layers
A DBMS separates concerns into three layers to ensure data independence.
graph TD
A["External Schema"] -->|"Mapping 1: Logical Data Independence"| B["Conceptual Schema"]
B -->|"Mapping 2: Physical Data Independence"| C["Internal Schema"]
A -->|"User View"| D["What users see (e.g., 'Find students in Pokhara')"]
B -->|"Global View"| E["Unified data model (e.g., Student, Course tables)"]
C -->|"Physical Storage"| F["How data is stored (e.g., B-tree indexes)"]Key Definitions
- Logical Data Independence: Change the conceptual schema without affecting external views.
Example: Adding a
Facultycolumn toStudentdoesn’t break user queries. - Physical Data Independence: Change storage (e.g., from HDD to SSD) without changing conceptual schema.
6. Real-World Applications
In the Real World
eSewa/Khalti (Payment Gateways)
- Idea: Relational schema for transactions (e.g.,
Transaction(ID, UserID, Amount, Status)). - How: Ensures atomicity (no partial payments) and avoids redundancy (e.g., storing user details in one table).
- Idea: Relational schema for transactions (e.g.,
Daraz (E-commerce)
- Idea: Functional dependencies in
Order(OrderID → CustomerID, ProductID). - How: Prevents anomalies like updating a customer’s address in multiple orders.
- Idea: Functional dependencies in
NTC/Ncell (Telecom)
- Idea: Three-schema architecture separates:
- External: "Show my bill."
- Conceptual:
Customer(Phone, Plan), Bill(Phone, Date, Amount). - Internal: Physical storage on RAID arrays.
- Idea: Three-schema architecture separates:
7. Worked Example: Bank Loan Database
Schema:
CREATE TABLE Loan {
LoanID INT PRIMARY KEY,
CustomerID INT REFERENCES Customer(CID),
Amount DECIMAL(10,2),
InterestRate DECIMAL(5,2)
};
Instance (2024 Q1):
| LoanID | CustomerID | Amount | InterestRate |
|---|---|---|---|
| 1001 | 5001 | 50000.00 | 6.5 |
Functional Dependencies:
LoanID → (CustomerID, Amount, InterestRate)(unique loan).CustomerID → Name(fromCustomertable).
Quality Check:
- No Redundancy:
InterestRateisn’t duplicated per customer. - No Update Anomaly: Changing
InterestRatefor all loans of a customer requires a single update.
8. Exam Tip
Focus Areas:
- Define terms: Schema vs. instance (always give an example).
- Draw diagrams: ER diagrams, three-schema layers, or FD examples.
- Compare models: Relational vs. flat files (highlight SQL vs. manual parsing).
- Apply quality measures: Identify anomalies in given schemas.
- Real-world links: Tie FD/three-schema to eSewa, Daraz, or NTC.
Common Pitfalls:
- Confusing logical vs. physical independence.
- Forgetting to include primary keys in FD examples.
- Overlooking atomicity in quality measures (e.g., splitting
AddressintoStreet,City).
Sample Question Breakdown:
- 20 marks: Define schema/instance + draw ER diagram (4 marks each).
- 15 marks: Explain three-schema architecture with a diagram (8) + FD example (7).
- 10 marks: Compare relational vs. flat file (5) + quality measures (5).
9. Summary Table: Key Concepts
| Concept | Definition | Example |
|---|---|---|
| Data Model | Blueprint for data organization. | Relational (tables), hierarchical (trees). |
| Schema | Structure of the database (tables, columns). | Student(SID, Name) |
| Instance | Actual data at a point in time. | List of students in 2024. |
| Functional Dependency | X → Y means X determines Y. |
SID → SName |
| Three-Schema | External → Conceptual → Internal layers. | eSewa’s user view → transaction tables → storage. |
Based on the TU BIT syllabus for Database Management System (BIT202), unit 2.
Discussion
Loading…