Cambridge IGCSE0417

Create a database structure

Information Communication Technology 0417 Chapter Notes

What this chapter covers

Create a database structureManipulate dataPresent data
ShareWhatsAppPost
Create a database structure notes

Unable to load PDF

The notes viewer could not load. Please refresh the page.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Create a database structure notes as text: skim, search, and jump between subtopics.

~11 min read

1. Database Fundamentals: Fields, Records, Tables

A database stores organised data in one or more tables. Think of a table like a grid. Each column in the grid is called a 'field', which stores a single piece of information, like 'FirstName' or 'EmailAddress'. Each row in the grid is called a 'record', which is a complete set of information for one person or item, containing all the field data for that single entry. The entire grid of fields and records is called a 'table'.

Key term

Record: A complete set of fields for a single person or item in a database table, represented as a row.

Examiner insight

Examiners award marks for using the terms 'field' and 'record' correctly and distinctly in your answers. Avoid vague terms like 'box' or 'line'.

Common pitfall

Confusing a 'field' (a column, one type of data) with a 'record' (a row, all data for one entry). Remember: Fields are vertical, Records are horizontal.

Fun fact

The world's largest database, the World Data Centre for Climate, holds over 220 terabytes of data, which is equivalent to all the books in the world's largest libraries combined, several times over!

Worked example 12 marks

The table below stores details of library members.

MemberIDFirstNameSurnamePostcode
101SarahKhanSW1A 0AA
102BenJonesW1A 1AA

i) Identify and copy out one field name. [1] ii) Identify and copy out one complete record. [1]

  1. 1

    i) A field is a single column heading that describes the data. Any of the following are correct: MemberID, FirstName, Surname, Postcode.

  2. 2

    ii) A record is a complete row of data for one member. Either of the following is correct: 101, Sarah, Khan, SW1A 0AA OR 102, Ben, Jones, W1A 1AA.

Recap

  • A database is an organised collection of data.
  • Data is stored in tables, which are made up of columns and rows.
  • A column in a table is called a field and represents one type of information.
  • A row in a table is called a record and represents all the information about one item.
  • A table is a collection of records about a specific entity, like 'Students' or 'Products'.

Quick check

  1. What is the term for a single column in a database table?1 mark
  2. What is the term for a single row in a database table?1 mark

2. Choosing the Right Data Types

When you create a field in a database table, you must assign it a 'data type'. This tells the database what kind of data to expect and how to handle it. Choosing the correct data type is crucial for data integrity and efficient processing. For example, you can't perform mathematical calculations on a field set to 'Text'. Common data types include:

  • Text/Short Text: For names, addresses, and other text.
  • Number/Integer: For whole numbers used in calculations (e.g., Quantity).
  • Currency: For monetary values, automatically formatted with a currency symbol and two decimal places.
  • Date/Time: For storing dates and times in a specific format.
  • Boolean (Yes/No): For fields that can only have two values, such as True/False or Yes/No.

Key term

Data Type: A classification that specifies which type of value a field can hold, such as text, number, or date, which determines how the database stores and manipulates the data.

Examiner insight

Marks are often awarded for selecting the *most appropriate* data type for a given scenario and being able to justify the choice, especially for tricky cases like phone numbers.

Common pitfall

Using the 'Number' data type for identifiers like phone numbers or postcodes. This can cause problems as leading zeros are often removed and they are not used for calculations. 'Text' is almost always the better choice for these.

Fun fact

The 'Boolean' data type is named after George Boole, a 19th-century mathematician. His work on logic, using only True and False values, laid the foundations for all modern digital electronics and computing.

Worked example 15 marks

A school wants to create a database table to store student details. Suggest the most appropriate data type for each of the following fields:

  • StudentID
  • DateOfBirth
  • FeesPaid
  • NumberOfSiblings
  • EmergencyContactPhoneNumber
  1. 1

    StudentID: Text. Although it may contain numbers, it is an identifier and will not be used for calculations. Using 'Text' allows for leading zeros or letters (e.g., 'S001').

  2. 2

    DateOfBirth: Date/Time. This ensures dates are entered in a valid format and allows for calculations like age.

  3. 3

    FeesPaid: Boolean (Yes/No). This is a simple yes or no question, making Boolean the most efficient choice.

  4. 4

    NumberOfSiblings: Number/Integer. This is a whole number that might be used in statistical calculations.

  5. 5

    EmergencyContactPhoneNumber: Text. Phone numbers often contain spaces, brackets, or start with a '0', which would be removed by a 'Number' data type. They are not used for calculations.

Recap

  • Every field in a database must have a data type.
  • The data type determines the kind of data that can be stored in a field.
  • Common data types are Text, Number, Date/Time, Currency, and Boolean.
  • Choosing the correct data type is essential for data validation and performing calculations.
  • Use 'Text' for identifiers like phone numbers or postcodes that won't be used in calculations.

Quick check

  1. What is the most appropriate data type for a field that will store the price of an item?1 mark

3. The Primary Key: A Unique Identifier

Every table in a database needs a 'primary key'. A primary key is a field (or a combination of fields) that contains a unique value for each record. This ensures that every record can be uniquely identified, just like a National Insurance number identifies a unique person. Two records in a table can never have the same primary key value. Furthermore, the primary key field cannot be left empty (it cannot be 'null'). Often, an 'AutoNumber' data type is used to automatically generate a new, unique number for each record added, making it a perfect primary key.

Key term

Primary Key: A field in a table which uniquely identifies each record in that table.

Examiner insight

To earn full marks when explaining why a field is unsuitable as a primary key, you must explicitly state that it could contain duplicate/non-unique values. Simply saying 'two people could have the same name' is a perfect answer.

Common pitfall

Choosing a field like 'Surname' or 'DateOfBirth' as a primary key. Many people can have the same surname or be born on the same day, so these fields are not unique and are unsuitable.

Worked example 15 marks

A cattery owner creates a table to store details of cats. The fields are: `Name`, `Gender`, `Weight(Kg)`, `Breed`.

i) Explain what is meant by a primary key. [2] ii) Explain why none of the existing fields are suitable to be the primary key. [2] iii) Suggest a suitable new field that could be added to act as the primary key. [1]

  1. 1

    i) A primary key is a field that uniquely identifies every record in a table. Its value must be different for every record and cannot be left blank.

  2. 2

    ii) None of the fields are suitable because they could all contain duplicate data. For example, two cats could have the same name ('Smokey'), be the same gender, have the same weight, or be the same breed. A primary key must be unique for every record.

  3. 3

    iii) A suitable new field would be `CatID` or `AnimalID`. This could be set to AutoNumber to ensure each new cat entered gets a unique number.

Recap

  • A primary key is a field that uniquely identifies each record in a table.
  • The value in a primary key field must be unique for every record.
  • A primary key field cannot be empty (null).
  • Primary keys are essential for preventing data duplication and for linking tables together.
  • A field like 'Surname' is a poor choice for a primary key as it is not guaranteed to be unique.

Quick check

  1. State two properties of a primary key field.2 marks

4. Flat-File vs. Relational Databases

There are two main ways to structure a database. A 'flat-file' database stores all data in one single, large table. This is simple to set up for small amounts of data but quickly becomes problematic. The main issue is 'data redundancy' – the same information (like a customer's name and address) is repeated for every purchase they make. This wastes space and can lead to 'data inconsistency', where updating the address in one place but not another creates conflicting information. A 'relational' database solves this by splitting data into multiple, smaller tables based on themes (e.g., a 'Customers' table and an 'Orders' table). These tables are then linked, which reduces data redundancy and improves data integrity, making the database more efficient and reliable.

Key term

Data Redundancy: When the same piece of data is stored unnecessarily in multiple places within a database.

Examiner insight

Examiners look for a clear understanding of the disadvantages of flat-file databases (like data redundancy and inconsistency) as a justification for using a more complex relational model.

Common pitfall

Simply stating that relational databases have 'linked tables' without explaining the benefits this brings, such as reduced data duplication and improved data integrity.

Worked example 15 marks

A small shop stores all its sales data in a single table with the fields: `SaleID`, `CustomerName`, `CustomerEmail`, `ItemName`, `ItemPrice`, `DateOfSale`.

i) Is this a flat-file or a relational database? [1] ii) Identify one example of data redundancy that would occur in this table. [1] iii) Explain how you could use a relational approach to improve this structure. [3]

  1. 1

    i) This is a flat-file database, as all the data is stored in one table.

  2. 2

    ii) Data redundancy would occur with the customer's details. If the same customer buys multiple items, their `CustomerName` and `CustomerEmail` will be typed in and stored repeatedly for every single sale.

  3. 3

    iii) You could use a relational approach by creating two tables. A `Customers` table with fields `CustomerID` (Primary Key), `CustomerName`, and `CustomerEmail`. A second `Sales` table would have fields `SaleID` (Primary Key), `CustomerID` (as a link), `ItemName`, `ItemPrice`, and `DateOfSale`. This way, each customer's details are only stored once.

Recap

  • A flat-file database stores all data in a single table.
  • Flat-file databases suffer from data redundancy and potential data inconsistency.
  • A relational database stores data in multiple, linked tables.
  • Relational databases reduce data redundancy and improve data integrity.
  • Splitting data into themed tables (like Customers, Products, Orders) is the core idea of a relational database.

Quick check

  1. State one major disadvantage of using a flat-file database.1 mark

5. Linking Tables with Foreign Keys

In a relational database, tables are linked together using keys. We know a 'primary key' uniquely identifies a record in its own table. A 'foreign key' is a field in one table that is a copy of the primary key from another table. This creates the link. For example, imagine a 'Students' table with a primary key `StudentID`, and a 'Locker_Allocations' table. To assign a locker to a student, we would add a `StudentID` field to the `Locker_Allocations` table. In this table, `StudentID` is the foreign key. It 'points' back to the original `StudentID` in the `Students` table, creating a relationship. This typically forms a 'one-to-many' relationship: one student (the 'one' side) can be linked to many entries in another table (e.g., one student could borrow many library books).

Key term

Foreign Key: A field in one table that refers to the primary key in another table, used to create a link between the two tables.

Examiner insight

When asked to describe how to set up a relationship, candidates must clearly identify the primary key in the 'one' table and state that it should be added as a foreign key to the 'many' table.

Common pitfall

Confusing the primary key and the foreign key's location. The primary key is in the 'one' side of a relationship (e.g., one customer), and the foreign key is added to the 'many' side (e.g., many orders).

Worked example 14 marks

A database has two tables, `tbl_Tutor` and `tbl_Student`. `tbl_Tutor` has fields: `TutorID` (Primary Key), `TutorName`, `Subject`. `tbl_Student` has fields: `StudentID` (Primary Key), `StudentName`, `DateOfBirth`.

Explain how you would create a one-to-many relationship to show which tutor is assigned to each student. You must name the tables and fields you would use.

  1. 1

    To create the relationship, you need to place a foreign key in the table on the 'many' side of the relationship. Here, one tutor can have many students.

  2. 2

    Therefore, the `tbl_Student` table is the 'many' side.

  3. 3

    You would add the primary key from `tbl_Tutor`, which is `TutorID`, into the `tbl_Student` table.

  4. 4

    In the `tbl_Student` table, the `TutorID` field would be the foreign key.

  5. 5

    This creates a link between `tbl_Tutor.TutorID` and `tbl_Student.TutorID`, establishing the one-to-many relationship.

Recap

  • Relational databases use foreign keys to link tables.
  • A foreign key is a primary key from one table used in another table to create a relationship.
  • The most common type of relationship is 'one-to-many'.
  • The foreign key is placed in the table on the 'many' side of the relationship.
  • Relationships ensure data integrity by linking related data without duplicating it.

Quick check

  1. In a one-to-many relationship between `tbl_Customer` and `tbl_Order`, in which table would you place the foreign key?1 mark

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. In the context of a database, define the terms 'field' and 'record'.2 marks
  2. A database table is created to store details of cars for sale. Suggest a suitable field that could be used as a primary key and justify your choice.2 marks
  3. A table contains the following fields for a sports club: `MemberID`, `JoinDate`, `Fee`, `IsJunior`, `FirstName`. Suggest the most appropriate data type for each field.5 marks
  4. Explain two reasons why 'FirstName' would be an unsuitable choice for a primary key in a database of a large company's employees.2 marks
  5. Explain the difference between a flat-file database and a relational database, mentioning one advantage of the relational model.3 marks
  6. What is data redundancy and why is it considered a problem in database management?2 marks
  7. A doctor's surgery has a `PATIENTS` table with `PatientID` as the primary key, and an `APPOINTMENTS` table. Explain how you would link these two tables to show which patient has which appointment. Identify the primary key, the foreign key, and the table where the foreign key should be placed.4 marks
  8. A database for a video streaming service uses a single table with the fields: `UserID`, `UserName`, `UserEmail`, `SubscriptionDate`, `MovieID`, `MovieTitle`, `Genre`, `DateWatched`. Identify two specific problems with this flat-file structure and explain how you would redesign it using a relational approach with at least two tables.6 marks
  9. What is a foreign key and what is its purpose in a relational database?2 marks
  10. State the most appropriate data type for a field named 'OnSale' which will store whether a product is currently on sale or not.1 mark

Go deeper

Practise and revise with member-only material for this chapter.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters