MySQL + SQL · Lesson 4

File System vs DBMS

What is a File System?

File System is the traditional method of storing data in separate files on a computer — such as text files, Excel sheets, or Word documents. Each department manages its own files independently, with no central control or connection between files.

Examples of File System usage:

  • School keeps student list in one Excel file, fee records in another, and library records in a third — all separate.
  • Office stores employee data in Word documents and salary in a calculator file.
  • No automatic connection between files — manual work required to combine them.

What is DBMS?

DBMS (Database Management System) is software that stores, manages and retrieves data in a structured, centralized database. It provides security, concurrent access, data integrity and easy querying through SQL.

Examples: MySQL, Oracle, MS SQL Server, PostgreSQL, MS Access.

  • All school data in one database — students, fees, library, attendance all linked.
  • Any authorized user can query data instantly with SQL.
  • Multiple users access simultaneously without data conflict.

File System vs DBMS – Full Comparison

FeatureFile SystemDBMS
Data StorageSeparate, unconnected filesCentralized, structured database
Data RedundancyHigh — same data in many filesLow — data stored once, linked by keys
Data InconsistencyHigh — updating one file doesn't update othersLow — one update reflects everywhere
Data SharingDifficult — files must be manually sharedEasy — multiple users query same database
Data SecurityNo user-level access controlRole-based permissions (admin, teacher, student)
Data IntegrityNo automatic constraintsPRIMARY KEY, NOT NULL, CHECK, FOREIGN KEY
Concurrent AccessTwo users editing same file = data lossTransactions + locking prevent conflicts
Backup & RecoveryManual copy of files — error-pronemysqldump, automated backup tools
Query/SearchManual searching through file contentsSQL SELECT — instant search with conditions
Crash RecoveryData lost if system crashes during writeTransaction rollback saves data on crash
ScalabilityVery poor — slow as files growGood — indexes and optimization handle large data
CostLow initial setupHigher setup but lower long-term cost

Problems of File System (Detailed)

1. Data Redundancy: Student name stored in fee file, result file and library file separately. If name has a typo, it must be corrected in all 3 files manually.

2. Data Inconsistency: Student address updated in fee register but forgotten in library card → two different addresses for same student → which is correct?

3. Data Isolation: Fee file in Excel, library in Word, attendance in paper register → impossible to combine and analyze together.

4. No Concurrent Access: Two clerks open the same Excel fee file → one overwrites the other's changes → data loss.

5. Security Issues: Any teacher with computer access can open fee records, modify salary data, or delete important files accidentally.

6. No Integrity Rules: A student's marks can be entered as "abc" or -50 — file system doesn't prevent it.

7. Difficult Querying: To find "students from Khurja who paid fee and have overdue library books" — manually search 3 files and cross-reference → hours of work vs. 1 SQL JOIN query in DBMS.

SQL Demo – DBMS Solves File System Problems

-- In DBMS: One database, all data connected
CREATE DATABASE school_db;
USE school_db;

CREATE TABLE students (
  roll_no INT PRIMARY KEY,        -- integrity: no duplicate students
  name VARCHAR(80) NOT NULL,      -- integrity: name cannot be blank
  city VARCHAR(50)
);

CREATE TABLE fee_records (
  fee_id INT PRIMARY KEY AUTO_INCREMENT,
  roll_no INT NOT NULL,
  amount DECIMAL(10,2),
  paid_date DATE,
  FOREIGN KEY (roll_no) REFERENCES students(roll_no)  -- no orphan records
);

CREATE TABLE library (
  lib_id INT PRIMARY KEY AUTO_INCREMENT,
  roll_no INT,
  book_name VARCHAR(100),
  return_date DATE,
  FOREIGN KEY (roll_no) REFERENCES students(roll_no)
);

INSERT INTO students VALUES (1,'Aarav Sharma','Khurja'),(2,'Priya Verma','Aligarh');
INSERT INTO fee_records (roll_no,amount,paid_date) VALUES (1,5000,'2025-04-10'),(2,5000,'2025-04-15');
INSERT INTO library (roll_no,book_name,return_date) VALUES (1,'Physics NCERT','2025-05-01');

-- Complex query that would take hours in file system — seconds in DBMS
SELECT s.name, s.city, f.amount AS fee_paid, l.book_name AS book_borrowed
FROM students s
JOIN fee_records f ON s.roll_no = f.roll_no
LEFT JOIN library l ON s.roll_no = l.roll_no
WHERE s.city = 'Khurja';
Output — instant, combined result from 3 "files" (tables):
+--------------+--------+----------+-----------------+
| name | city | fee_paid | book_borrowed |
+--------------+--------+----------+-----------------+
| Aarav Sharma | Khurja | 5000.00 | Physics NCERT |
+--------------+--------+----------+-----------------+
File system: search 3 files manually. DBMS: one SQL query, instant result.

Common Mistakes

  • Thinking file system is always worse: For very small, simple, one-user data — files can work. DBMS overhead isn't always needed.
  • Not using foreign keys in DBMS: Without foreign keys, DBMS behaves like a file system — no referential integrity.
  • Confusing DBMS with Database: Database is the data; DBMS is the software that manages it (MySQL is DBMS, school_db is Database).
  • Not setting user privileges: Installing MySQL and giving everyone root access defeats the security advantage of DBMS.

Practice Tasks

  1. Draw a diagram showing how a school stores data in File System vs DBMS — show connections between fee, library and student data.
  2. List 5 specific problems a school would face if it used only Excel files for student data. For each problem, write how DBMS solves it.
  3. Create the school_db from the SQL demo above. Write a query to find all students who have a library book pending return.
  4. Viva: "What is data redundancy? Give an example from a file system." — Write a 3-line answer.

Summary

  • File System = Separate files, no control, high redundancy, poor security.
  • DBMS = Centralized, structured, secure, concurrent, with SQL querying.
  • DBMS solves: Redundancy, Inconsistency, Isolation, Security, Integrity, Concurrency issues.
  • Key DBMS examples: MySQL, Oracle, MS SQL Server, PostgreSQL.
  • In real projects: Always use DBMS for multi-user, multi-table, scalable applications.