Computer ScienceCore18 min read

Data Basics

What data is, how it is stored, and why files stopped being enough

This topic appears in:

01

From data to information

Data is raw, unprocessed facts: 21, Ali, 72. It has no meaning until someone says what the numbers are. Information is data with that context supplied — roll number 21, named Ali, scored 72 in physics. Knowledge is what you can then do with it: Ali is in the top quarter of the class and needs no extra support.

Everything in this chapter and the next six exists to move data along that chain reliably, for many users, without losing any of it.

TermMeaning
Fieldone item of data — a name, a mark, a date
Recordall the fields describing one thing — one student
File / tablea collection of records of the same type
Databasea set of related tables, managed together
Entitya real thing the database stores data about
Attributea property of an entity — its fields
02

Data types, and choosing them properly

Every field has a data type, which decides what may be stored, how much space it takes, and what operations are allowed. Choosing well is not fussiness — a badly chosen type either rejects valid data or accepts nonsense.

The rule of thumb: store a value as a number only if you will do arithmetic on it. A phone number is text, despite consisting of digits, because you never add two phone numbers and because a leading zero would be lost.

TypeHoldsUse for
Text / varcharcharactersnames, addresses, phone numbers
Integerwhole numbersquantities, marks, counts
Decimal / realfractional numbersprices, measurements, averages
Date / timecalendar valuesbirth dates, timestamps
Booleantrue or falsepresent/absent, paid/unpaid
Currencymoney to fixed precisionfees, salaries

Why a phone number is not a number

Stored as a number, 0300 1234567 loses its leading zero, cannot hold a dash or a space, and might silently be rounded. Stored as text it keeps every character exactly. The test is always the same: if you would never do arithmetic on it, it is text — which also covers roll numbers, product codes and national identity numbers.

03

Why flat files were abandoned

Before databases, each program kept its own file. The library kept a student file, the examinations office kept another, the accounts office a third. That arrangement produces five specific problems, and the syllabus expects them by name.

  • Data redundancy — the same student's address stored in three files.
  • Data inconsistency — the address is updated in one file and not the others, so the system now holds two different answers and no way to tell which is right.
  • Data dependence — each program contains the file's layout, so adding a field means editing every program that reads it.
  • Poor sharing and security — access is all or nothing at the file level; you cannot let the library see names but not marks.
  • Difficult ad-hoc queries — answering a question nobody anticipated means writing a new program.

Inconsistency is the one that really hurts

Redundancy wastes space, which is cheap. Inconsistency destroys trust: once two files disagree about an address, nobody can tell which is correct without going back to the student, and every report drawn from either is suspect. A database stores each fact once, so the question cannot arise — and that, rather than saving disk space, is the argument for it.

04

What a database gives you instead

A database stores related data once, in a structured form, managed by software that every program goes through rather than around. That single change addresses all five problems.

Each fact is stored in one place, so there is nothing to become inconsistent. Programs ask the management software for data rather than reading a file layout, so the structure can change without rewriting them. Permissions are set per user and per table. And a query language answers new questions without new programs.

Worked example

A school keeps student details in the library system, the examination system and the fee system as three separate files. A student moves house. Explain what goes wrong and how a database prevents it.

  1. The address must be changed in three places, by three different people.Nothing connects the three files, so nothing propagates a change.
  2. If one is missed, the system holds two different addresses — data inconsistency.This is not a hypothetical: in practice at least one always is missed.
  3. Fee reminders now go to the old address while examination results go to the new one, and neither office knows the other disagrees.The consequence is invisible until something goes wrong for the student.
  4. In a database the address is stored once in the STUDENT table, and all three systems read that one record.One update, and every system sees it immediately.
  5. The fact is stored once, so there is no second copy to disagree with.This is what "eliminating redundancy" is actually for.

Three copies mean three updates and at least one missed — inconsistency. A database stores the address once.

Before you leave this chapter

  1. Field → record → table → database. An entity is the real thing; attributes are its fields.
  2. Store as a number only what you would do arithmetic on. Phone numbers are text.
  3. Flat files cause redundancy, inconsistency, data dependence, poor security and difficult queries.
  4. Inconsistency is the serious one — it destroys trust in every report.
  5. A database stores each fact once and mediates all access through management software.

Practice questions

6 questions · 20 marks · full working on every one

Try each one on paper first, then open the working. The marks are shown where they are actually awarded, because that is where they are actually lost.

Short questions

3 · 6 marks

Two marks each, in the style of the short-question section of the paper. Answer in two or three lines.

SQ1[2 marks]
Define a field, a record and a table.
Model answer

A field is a single item of data, such as a student's name. A record is the complete set of fields describing one entity — all the details of one student. A table is a collection of records of the same type.

Examiner tip. Use one running example through all three. It shows the containment relationship without needing to state it separately.

SQ2[2 marks]
Why should a telephone number be stored as text rather than as a number?
Model answer

A numeric type would discard a leading zero, could not store spaces or dashes, and might round the value. No arithmetic is ever performed on a telephone number, so nothing is gained by making it numeric.

Examiner tip. The leading zero is the concrete example that settles this instantly, and Pakistani mobile numbers all begin with one.

SQ3[2 marks]
What is data redundancy, and why is data inconsistency worse?
Model answer

Redundancy is the same data stored in more than one place. Inconsistency is what happens when one copy is updated and another is not, so the system holds conflicting values. Redundancy wastes storage, which is cheap; inconsistency means no report can be trusted, because there is no way to tell which copy is correct.

Examiner tip. Naming inconsistency as the consequence of redundancy shows the connection between the two, which is what the question is really testing.

Solved numericals

2 · 8 marks

Full working, one step per line, with the marks shown where they are awarded.

N1[4 marks]
State four disadvantages of storing data in separate flat files rather than a database.
Full working
  1. Redundancy — the same data is duplicated across several files[1]
  2. Inconsistency — updating one copy and not another leaves conflicting values[1]
  3. Data dependence — the file layout is embedded in each program, so a change to the structure means editing every program[1]
  4. Poor security and sharing — access is all-or-nothing per file; also accept difficulty answering unanticipated queries[1]

Redundancy, inconsistency, data dependence, and poor security or difficult queries.

Examiner tip. Name each problem with the standard term. Describing the symptom without the term usually earns half.

N2[4 marks]
A shop records sales. State a suitable data type for each field and justify two of your choices: ProductCode, Quantity, Price, DateSold.
Full working
  1. ProductCode — text, since it may contain letters and leading zeros and is never used in arithmetic[1]
  2. Quantity — integer, since you cannot sell a fraction of an item and it is counted[1]
  3. Price — decimal or currency, since it has a fractional part and must keep exact precisiona float can introduce rounding errors in money[1]
  4. DateSold — date, so that date arithmetic and sorting work correctly, which they would not on text[1]

Text, integer, currency, date — each justified by what will be done with it.

Examiner tip. Storing a date as text is the classic error. "01/02/2026" sorts alphabetically, so the system cannot tell which of two dates is earlier.

Long questions

1 · 6 marks

Theory and numerical together, as they appear in the long-question section.

LQ1[6 marks]
A hospital currently keeps patient details in three separate systems: reception, pharmacy and billing.
  1. Explain two problems this causes.
  2. Explain how a single database would address them.
  3. State one problem a database does NOT solve.
Mark scheme
  1. Redundancy — each patient's name, address and identifier are stored three times[1]
  2. Inconsistency — a change of address entered at reception does not reach pharmacy or billing, so the systems disagree and nobody knows which is rightin a hospital this can affect care, not just correspondence[1]
  3. A database stores each patient record once, so there is only one copy to update and no second copy to disagree with[1]
  4. All three departments read the same record, so a change is visible everywhere immediately[1]
  5. Permissions can be set per table or per field, so pharmacy sees prescriptions and billing does notbetter than all-or-nothing file access[1]
  6. A database does not fix incorrect data entry — if the address is typed wrongly it is now wrong everywhere at once, so validation at entry is still essentialthe honest limitation[1]

(a) redundancy and inconsistency (b) one stored copy, seen by all, with per-table permissions (c) it cannot prevent wrong data being entered — and now the error is everywhere

Examiner tip. Part (c) is the mark that separates a memorised answer from an understood one. Centralising data centralises the mistakes too.