Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Unit 6 B2: Relationships and data entry forms

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

50 minutes

Member 99 does not exist

Oakfield Youth Club is made up. Its sign-up list says member 99 joined Chess. The club has no member 99.

Somebody typed the wrong number and nothing stopped them. A relationship between tables stops this, and a good form makes it hard to happen.

By the end of this lesson

Note

I can link two tables with a foreign key (a field that points to another table) and say what a form button does.

Key words

WordWhat it means
Relationshipa link between two tables
One-to-manyone record in one table matches many in another
Many-to-manymany records in each table match many in the other
Linking tablea table that joins two tables with two foreign keys
Primary keya field that is different for every record
Foreign keya field that holds a primary key from another table
Forma screen for adding, changing or deleting records

The cells students fill in are left blank in this preview.

Starter: what you already know

Have a go

Starter: what you already know

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

A foreign key links two tables

A relationship is a link between two tables. In a one-to-many link, one record matches many in the other table. One member can have many sign-ups.

In a many-to-many link, each side has many matches. A member joins many activities and an activity has many members. Add a linking table in the middle. It holds two foreign keys, one to each table.

Try it: follow the links

Code: sql
-- signups holds two foreign keys. JOIN follows them to the other tables.
SELECT members.first_name, activities.activity_name
FROM signups
JOIN members ON signups.member_id = members.member_id
JOIN activities ON signups.activity_id = activities.activity_id
ORDER BY members.first_name, activities.activity_name;

-- Change the ORDER BY to put the activities in order first.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

8 more parts of this lesson are in the full lesson, which colleges teach from the Library. A college account gives your students all of it.