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

Free lesson

Data minimisation: collect less data

After this lesson: I can reduce the personal data a system collects and shares.

55 min lesson6 commandsMySQL and phpMyAdmin lab with a sample shop database to practise SQL

Why does a newsletter need a birth date?

Data minimisation means collecting only the personal data you need for a clear purpose. Data you never collect cannot leak, be misused or need deleting later.

A sign-up form for a newsletter needs one thing, an email address. Many forms also ask for a phone number, a birth date and a postcode, and every extra field is a risk.

By the end of this lesson

Note

I can reduce the personal data a system collects and shares.

Key words

WordWhat it meansExample
Data minimisationcollecting only what the purpose needs
Purposethe reason you collect the data
Viewa saved query that shows chosen columns
Generalisereplace a precise value with a broader one1994-03-18 becomes 1994
Need to knoweach person sees only what their job needs

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

Start with the purpose, then list needs

Write down why you collect the data. Then ask of each field: could we do this without it?

If the answer is yes, do not collect it. A field kept "in case it is useful" has no purpose yet, so it should not be there.

A purpose also limits use. Data collected to send a parcel is not free to be used for something else.

Worked example: what each purpose needs

PurposeNeededNot needed
Send a newsletterEmail addressPhone, birth date, postcode
Deliver a parcelName, address, a contact for the courierBirth date, health details
Check a buyer is an adultA yes or no answerThe full birth date
Count visitors by areaThe first part of the postcodeThe full postcode, the name

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

A view shows only needed columns

Not everyone in a company needs every column. The team that sends the newsletter does not need phone numbers.

A view is a saved query. People who read the view see its columns and nothing else. The table underneath stays as it is.

Use the first two lines from last time if your terminal is new, then make a view with three columns.

Accept the server's certificate

Command
printf '[client]\nssl-verify-server-cert=0\n' > ~/.my.cnf

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Make a short name for the shop

Command
alias sql='mariadb -h db -u student -pstudent shop -t -e'

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Make a view with three columns

Command
sql "CREATE OR REPLACE VIEW student_mailing AS SELECT id, first_name, country FROM customers"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Read the first three rows of the view

Command
sql "SELECT * FROM student_mailing ORDER BY id LIMIT 3"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ask the view for a column it lacks

Command
sql "SELECT email FROM student_mailing"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A view hides unselected columns

The first read prints customers 1, 2 and 3: Lucas in the United Kingdom, Ines in France and Elena in Ireland. Only id, first name and country exist in the view.

The second read fails with an error that says the column email is unknown. The view has no such column, so the team cannot see it.

A common mistake

Warning

Many people think a view locks the table. It does not. Anyone who can read the table can still read every column. A view protects only when people are given access to the view and not to the table.

Generalise a value to share less of it

Sometimes a team needs a rough value. A birth date can become a birth year, or an age band. A full postcode can become its first part.

The rough value still answers the question, such as "how many readers are under 30?", but it points at far fewer people.

Try it: broader versions of two values

Code: sql
-- Keep a broader version of two precise values.
SELECT id,
       SUBSTR(birth_date, 1, 4) AS birth_year,
       SUBSTR(postcode, 1, 3) AS area
FROM signups
ORDER BY id;
-- Change 1, 4 to 6, 2 to see the birth month instead of the year.

Remove the view when you finish

Command
sql "DROP VIEW student_mailing"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

About this lab and its source: MySQL and phpMyAdmin lab with a sample shop database to practise SQL

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.