Informatics Practices · Ch 6 — Database Concepts
File System to DBMS
File System to DBMS
A file system stores each department's data in its own separate file; a database stores all of it in one place as a set of related tables. The move from the first to the second is not just copying data across — the files have to be redesigned so that every fact is stored exactly once and tables can be connected through common columns. This section walks through that redesign using the school example, where the office maintained a STUDENT file (Table 7.1) and the class teacher maintained a separate ATTENDANCE file (Table 7.2).
How tables in a database connect
Tables in a database are linked (related) through one or more common columns or fields. In the school example, the STUDENT file and the ATTENDANCE file share two field names: RollNumber and SName. This overlap is the raw material for linking — but as it stands, it also duplicates data. Converting the two files into a proper database therefore needs three deliberate changes.
- Remove SName from ATTENDANCE. Since the student's name already lives in STUDENT, there is no need to repeat it in ATTENDANCE. Whenever the teacher needs a student's details, they can be retrieved through the common field RollNumber, which appears in both files. One fact, stored once.
- Split STUDENT into STUDENT and GUARDIAN. If two siblings study in the same class, the same guardian details (GName, GPhone and GAddress) get recorded twice — once with each sibling. That is redundancy, exactly the kind a database is meant to eliminate. The fix is to pull the guardian columns out into a separate GUARDIAN file, so each guardian's data is maintained only once, no matter how many children they have in the school.
- Add a unique GUID column. Splitting creates a new problem: two or more guardians can have the same name, so a name alone cannot tell us which guardian belongs to which student. The solution is an extra column, GUID (Guardian ID), which takes a unique value for each record in the GUARDIAN file. The same GUID column is also kept in the STUDENT file, and this shared column is what relates the two files.
Note
Guardians could also be told apart by their phone numbers — but a phone number can change, so it may not truly distinguish a guardian over time. A deliberately created ID that never changes is the safer identifier. This is a general principle when choosing identifying columns.
The resulting structure
Figure 7.1 shows the record structure of the three files in the STUDENTATTENDANCE database:
| File | Fields |
|---|---|
| STUDENT | RollNumber, SName, SDateofBirth, GUID |
| GUARDIAN | GUID, GName, GPhone, GAddress |
| ATTENDANCE | AttendanceDate, RollNumber, AttendanceStatus |
This diagram is not the complete database schema, because it shows only the record structures — it does not yet show the relationships among the tables.
The structures in Figure 7.1 are empty shells; they get populated with actual data as in Tables 7.4, 7.5 and 7.6. A snapshot of the STUDENT table:
| RollNumber | SName | SDateofBirth | GUID |
|---|---|---|---|
| 1 | Atharv Ahuja | 2003-05-15 | 444444444444 |
| 2 | Daizy Bhutia | 2002-02-28 | 111111111111 |
| 3 | Taleem Shah | 2002-02-28 | |
| 4 | John Dsouza | 2003-08-18 | 333333333333 |
| 5 | Ali Shah | 2003-07-05 | 101010101010 |
| 6 | Manika P. | 2002-03-10 | 466444444666 |
A snapshot of the GUARDIAN table:
| GUID | GName | GPhone | GAddress |
|---|---|---|---|
| 444444444444 | Amit Ahuja | 5711492685 | G-35, Ashok Vihar, Delhi |
| 111111111111 | Baichung Bhutia | 3612967082 | Flat no. 5, Darjeeling Appt., Shimla |
| 101010101010 | Himanshu Shah | 4726309212 | 26/77, West Patel Nagar, Ahmedabad |
| 333333333333 | Danny Dsouza | S-13, Ashok Village, Daman | |
| 466444444666 | Sujata P. | 3801923168 | HNO-13, B-block, Preet Vihar, Madurai |
And the ATTENDANCE table records one row per student per date, with status P (present) or A (absent) — for example, on 2018-09-01 roll numbers 1, 2, 4 and 6 were present while 3 and 5 were absent; on 2018-09-02 roll numbers 1, 2, 5 and 6 were present while 3 and 4 were absent.
Notice how the split pays off: each guardian's name, phone and address appear exactly once in GUARDIAN, and STUDENT simply points to the right guardian through GUID.
One central repository, many users
Figure 7.2 shows the simplified STUDENTATTENDANCE database maintaining data about students, guardians and attendance. The DBMS keeps a single repository of data at a centralized location, and that one repository can be used by multiple users at the same time — the office staff and the teacher no longer maintain private copies; both work on the same data.
How users interact with a DBMS …
The figure shows the record structure of the STUDENTATTENDANCE database as three side-by-side rectangular boxes, one per data file, each topped by a dark title bar carrying the file's name. The STUDENT box lists the fields RollNumber, SName, SDateofBirth and GUID. The GUARDIAN box lists GUID, GName, GPhone and GAddress. The ATTENDANCE box lists AttendanceDate, RollNumber and AttendanceStatus. The boxes are empty — they show only field names, no data — because at this stage the structure is being designed; the actual rows come later when the tables are populated.
This three-file layout is the outcome of converting the school's two original files into a database-ready design. First, SName was dropped from the attendance file: since RollNumber appears in both STUDENT and ATTENDANCE, a student's name can always be retrieved through that common field, so storing it twice would be pointless duplication. Second, the original student file was split into STUDENT and GUARDIAN, so that when two siblings study in the same class their guardian's name, phone and address are stored only once instead of being repeated for each child. Third, because two or more guardians can share the same name — and a phone number is unreliable as an identifier since it can change — a new column GUID (Guardian ID) was created to take a unique value for each guardian record; the same GUID column is also kept in STUDENT so the two files can be related. …
| RollNumber | SName | SDateofBirth | GUID |
|---|---|---|---|
| 1 | Atharv Ahuja | 2003-05-15 | 444444444444 |
| 2 | Daizy Bhutia | 2002-02-28 | 111111111111 |
| 3 | Taleem Shah | 2002-02-28 | |
| 4 | John Dsouza | 2003-08-18 | 333333333333 |
| GUID | GName | GPhone | GAddress |
|---|---|---|---|
| 444444444444 | Amit Ahuja | 5711492685 | G-35, Ashok Vihar, Delhi |
| 111111111111 | Baichung Bhutia | 3612967082 | Flat no. 5, Darjeeling Appt., Shimla |
| 101010101010 | Himanshu Shah | 4726309212 | 26/77, West Patel Nagar, Ahmedabad |
| 333333333333 | Danny Dsouza | S -13, Ashok Village, Daman |
| Date | RollNumber | Status |
|---|---|---|
| 2018-09-01 | 1 | P |
| 2018-09-01 | 2 | P |
| 2018-09-01 | 3 | A |
| 2018-09-01 | 4 | P |
| 2018-09-01 | 5 | A |
| 2018-09-01 | 6 | P |
| 2018-09-02 | 1 | P |
| 2018-09-02 | 2 | P |
| 2018-09-02 | 3 | A |