Database concepts

Computer Science AS · Databases. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science AS topics

The idea

In a file-based approach each program keeps its own files. The same data is stored many times (redundancy), copies stop matching (inconsistency) and the programs depend on the file structure. A relational database stores each fact once in linked tables.

An entity is a thing we store data about, and it becomes a table. A record (tuple) is a row and a field (attribute) is a column. Tables are linked when the primary key of one table appears as a foreign key in another.

Normalisation organises the tables step by step, from 1NF to 3NF, to remove redundancy.

In simpler words

In old file systems, each program kept its own files. The same data was stored many times, and copies stopped matching. A relational database keeps each fact once, in tables that link together. A table is a set of records about one kind of thing. A primary key picks out each record. A foreign key in another table links back to it.

An everyday comparison

A foreign key is like a student ID written on a library loan slip. The slip does not repeat the student's name and address; it just points to the student's record kept in one place. The comparison stops working because a database can enforce referential integrity, refusing any loan slip with an ID that does not exist, while a paper slip can carry any number at all.

Rules to remember

Common mistake

When a table has a single-field primary key, students look for a 2NF problem. A partial dependency is only possible with a composite key, so go straight to checking 3NF.

In the exam

For file-based problems, name them: redundancy, inconsistency, program-data dependence. For keys, define each precisely: primary key identifies each record uniquely; foreign key refers to the primary key of another table. For normalisation, work in order: 1NF (remove repeating groups), 2NF (remove partial dependencies on part of a composite key), 3NF (remove dependencies between non-key fields). Show each table with its primary key and any foreign keys. Replace many-to-many with a link table.

Worked example

LOAN(LoanID, BookID, BookTitle, DateOut) has primary key LoanID. Every field holds one value. Is the table in 3NF? If not, give a 3NF design.

  1. Every field holds one value, so it is in 1NF. The primary key is a single field, so there is no partial dependency and it is in 2NF.
  2. BookTitle depends on BookID, and BookID is not the key. This is a non-key dependency, so the table is not in 3NF.
  3. Move the dependent field to its own table with BookID as the primary key, and keep BookID in LOAN as a foreign key.

Answer: Not in 3NF. Use LOAN(LoanID, BookID, DateOut) and BOOK(BookID, BookTitle).

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Ethics and ownershipDatabase Management Systems (DBMS) →Take a Computer Science AS test