N3/N4  ·  ISDD  ·  Information Systems

Database Concepts

National 3 & National 4 Computing ScienceLesson ISDD1 of 9Approx 55 minBackground lesson
Learning intentions
  • Understand what tables, records and fields are
  • Explain why a primary key uniquely identifies each record
  • Recognise how related tables can be linked together
Success criteria
  • I can label the parts of a database table correctly
  • I can choose a sensible primary key for a table
  • I can describe why duplicate or unclear data causes problems
Warm up

Think about a school library system. It stores books, borrowers and loans.

Which item would be best as a unique identifier for one book?

Key vocabulary

Database
An organised collection of data that can be stored, searched and updated.
Table
A structure that stores data about one kind of thing, such as books, bikes or customers.
Field
One category of data in a table, shown as a column. Example: price.
Record
One complete item in a table, shown as a row.
Primary key
A field that uniquely identifies each record.
Foreign key
A field that stores a primary key from another table so records can be linked.

Tables, Records, Fields and Keys

Why databases use tables

A database stores information in a structured way. Instead of putting everything in one long document, a database separates information into tables. Each table describes one kind of thing. A bike shop database might have a bikes table, a customers table and an orders table.

Inside a table, fields are the headings and records are the entries. In a bikes table, fields could include bike_id, model, type and price. One record would hold the details for one bike.

Primary keys

A primary key is the field that uniquely identifies each record. Names and titles usually make poor primary keys because they can repeat. A generated ID, such as bike_id, is normally safer.

Links between tables

National 4 pupils must create a structure with links. In a relational database, a link is normally made by storing one table's primary key inside another table as a foreign key. For example, a bike_id in an orders table tells us which bike was ordered.

TermBike shop exampleWhy it matters
FieldmodelStores one category of data
RecordOne row for "Trail 200"Stores one complete item
Primary keybike_idIdentifies a bike uniquely
Foreign keytype_idLinks the bike to its type

Worked examples

Example 1 - spotting the record

In a table of mountain bikes, the whole row for "Trail 200" is one record. The model name alone is only one field value.

Example 2 - choosing a primary key

bike_id is better than model because two suppliers might sell bikes with the same model name. The key must not repeat.

Common mistakes
  • Calling a column a record. A column is a field; a row is a record.
  • Using a name as a primary key when it could repeat.
  • Putting several pieces of information into one field, such as "red mountain bike" instead of separate colour and type fields.
Tip

When you describe a database, use the exact vocabulary. "The table has fields for model, type and price" is much clearer evidence than "the database has information in it."

Task Set

Questions 1-3 are auto-checked. Questions 4-5 are self-marked evidence practice.

1. In a table, what is a field? TYPE 1

2. What is the main job of a primary key? TYPE 1

3. Which field is most suitable as a primary key for customers? TYPE 1

4. Explain the difference between a record and a field. TYPE 2

A field is one category of data in a table, such as price. A record is one complete row, holding all the field values for one item.

5. Draw a simple design for a bikes table with four fields. Mark the primary key. TYPE 2

Example: bike_id (primary key), model, bike_type, price.
Teacher notes - Shift+T to hide

Background lesson for N3 Information Solutions and N4 Information System Design and Development. It prepares pupils for N3 O1.1/O1.2 and N4 O1.1 but is not itself an assessed task.