UNIHIVE

Study Hub UNIPORT CSC 282

CSC 282 · Database Programming

Fields, records and files

The data hierarchy, field types, keys, fixed and variable length records, and kinds of files.

Our notes

2 min read

The data hierarchy

bit → byte (character) → field → record → file → database.

  • Field: one item of data about something: Surname, MatricNo, CGPA.
  • Record: all the fields about one thing: one student.
  • File: a collection of records of the same kind: all students.
  • Database: related files (students, courses, results) managed together.

Field types

TypeExampleNotes
text (character)Surname "Okoro"fixed or variable length
integerLevel 200no decimals
decimal / currencyFees 85000.00exact money values
date / timeDateOfBirthallows date arithmetic
BooleanHostel yes/no

Choose the type that matches how the field is used: phone numbers are text, not numbers (a leading 0 must stay, and you never add them).

Keys

  • Primary key: a field (or fields) that identifies each record uniquely: MatricNo.
  • Secondary key: a field used to search or sort that need not be unique: Department.
  • Foreign key: a field that refers to the primary key of another file (CourseCode in a results file).

Fixed and variable length records

  • Fixed length: every record takes the same space (e.g. 100 bytes). The position of record n is (n − 1) × 100: easy direct access, but space is wasted on short names.
  • Variable length: records take only what they need, with separators or a length count; saves space but you cannot jump straight to record n.

Kinds of files

  • Master file: permanent data, updated periodically.
  • Transaction file: changes waiting to be applied.
  • Reference (table) file: lookup data that rarely changes (course titles, fee rates).
  • Archive / backup file: old copies kept for recovery and history.
  • Log file: a record of what was done, by whom and when.

Example record layout

FieldTypeSize
MatricNotext13
Surnametext30
OtherNamestext40
Levelinteger3
CGPAdecimal4,2

Fixed record length = 13 + 30 + 40 + 3 + 4 = 90 characters (if numbers are stored as text). A file of 12,000 students takes 12,000 × 90 = 1,080,000 bytes, about 1 MB.

Exams usually ask

  • Define field, record, file and key with examples.
  • Draw a record layout and work out file size.
  • Explain master, transaction and reference files.

Common mistake

Using a name as the primary key. Two students can share a name; a key must be unique and should not change.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 282 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.