
From an order list to a database table
At the Golden Biscuit Tin, Jacques writes every biscuit order on a paper slip. Each slip shows an order number, the type of biscuit and how many were ordered. That works for four orders. It stops working when there are four hundred and someone asks, “Which orders were for Hobnobs?”
A database solves this by storing the same data in a table. Because every order is stored in the same layout, the data can be searched, sorted and totalled quickly.
Cambridge syllabus focus
Topic 9.1: define a single-table database using fields and records, suggest suitable basic data types, and understand the purpose of a primary key so you can identify a suitable one.
Turning the order list into a table
Every order becomes one row of the BiscuitOrders table. Each piece of information on the slip, such as the order number, gets its own named column.
Records, fields and values
The table below highlights one record, one field and one individual value. Learn the difference between these three words, because exam questions test it again and again.
| OrderID | BiscuitType | Quantity |
|---|---|---|
| 101 | Hobnob | 6 |
| 102 | Viennese Swirl | 4 |
| 103 | Hobnob | 8 |
| 104 | Hobnob | 2 |
- Record – one complete row holding all the data about one order. Record 102 is
102, Viennese Swirl, 4. - Field – one column holding one category of data for every record.
BiscuitTypeis a field. - Value – a single item of data where one record meets one field. Order 103's
Quantityvalue is8.
Check your understanding 1
How many records and how many fields does BiscuitOrders contain?
Reveal answer
4 records (one row per order) and 3 fields (OrderID, BiscuitType and Quantity). The heading row holds the field names. It is not a record.
Why OrderID is the primary key
A primary key is a field whose value is unique for every record, so it can identify exactly one record. In BiscuitOrders, the OrderID values are 101, 102, 103 and 104. No two orders share one, and every new order is given a new number. Tell the database “order 103” and it finds exactly one record.
BiscuitType cannot be the primary key, because Hobnob appears in three different records. Searching for “Hobnob” finds three orders, not one. Repeated values are normal in a field like this, because many customers order the same biscuit.
Quantity is not suitable either. The four values (6, 4, 8 and 2) happen to be different today, but nothing stops two future orders from both being for 6 biscuits.
Choosing suitable data types
Each field stores one type of data. The basic data types for Cambridge 0478 are text/alphanumeric, character, Boolean, integer, real and date/time.
| Field | Example value | Data type | Reason |
|---|---|---|---|
| OrderID | 101 | Integer | A whole-number code that identifies each order |
| BiscuitType | Viennese Swirl | Text / Alphanumeric | Letters and spaces |
| Quantity | 4 | Integer | A whole number of biscuits that can be used in calculations |
Worked example: adding a new order
A fifth order arrives for 5 Viennese Swirls. What changes in the table?
- A new record is added:
105, Viennese Swirl, 5. - The number of fields stays at 3. A new order needs a new row, not a new column.
- The number of records rises to 5.
- The new OrderID, 105, has not been used before. Giving this order the ID 101 again would break the primary key, because 101 would no longer identify one order.
Result: new data means new records. The structure (the fields) only changes if the business wants to store a new kind of information, such as an order date.
Check your understanding 2
The Quantity values 6, 4, 8 and 2 are all different. Why is Quantity still not a suitable primary key?
Reveal answer
A primary key must be unique for every record that will ever be stored. Two future orders could easily have the same quantity, so Quantity cannot be relied on to identify one record.
Common Cambridge exam mistakes
A primary key must be unique. Hobnob appears in three records, so BiscuitType cannot identify a single order. OrderID can.
This swaps rows and columns. Records are rows (there are 4) and fields are columns (there are 3). Do not count the heading row as a record.
Original FutureLogic exam-style practice
These are original teaching questions, not official Cambridge examination questions. The marks shown are a guide only.
Question 1 (2 marks)
Using the BiscuitOrders table, state a suitable data type for the BiscuitType field and for the Quantity field.
Reveal model answer
BiscuitType: Text / Alphanumeric (1)
Quantity: Integer (1)
Question 2 (3 marks)
Identify the most suitable primary key for the BiscuitOrders table. Justify your choice.
Reveal model answer
OrderID (1). Each OrderID value is unique, so no two orders share the same value (1). It can therefore identify exactly one record/order (1).
Also creditworthy: BiscuitType is unsuitable because values such as Hobnob are repeated.
Quick quiz
- What is a record?
- What is a field?
- Which field in BiscuitOrders is the primary key?
- What data type suits the Quantity field?
Quiz answers
Reveal all answers
- One row of a table, holding all the data about one item (here, one order).
- One column of a table, holding one category of data for every record.
- OrderID.
- Integer.
Final summary
Record
One row: all the data about one order.
Field
One column: one category of data, such as BiscuitType.
Primary key
A unique value that identifies each record: OrderID.
Data types
Integer, Text and Integer for the three fields.