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

Free lesson

OS 4.3 (11 of 12): Data dictionary and ERD

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Sign up for a club

A school has chess, football and drama clubs. A student can join many clubs. A club has many students.

What must the system remember? The name? The year? Which club? What if someone types year 20? In UK schools, the years go from 7 to 13.

Before you build tables, you write down every fact and every rule. This is the design step.

Key words

WordWhat it meansExample
DatabaseAn organised store of data that programs can search and change.
Data dictionaryA list of every field in the database, with its type, size and rules.
FieldOne fact in a table: one column.
Data typeThe kind of value a field holds.
ValidationA check that data is sensible before it is stored.year must be 7 to 13
Primary keyA field that is different for every row. It finds one row.
Foreign keyA field that holds the primary key of a row in another table.
EntityA thing the database stores facts about. Each one is a table.
ERDEntity relationship diagram. A picture of the tables and how they link.
One-to-manyOne row in table A links to many rows in table B.
Many-to-manyMany rows in table A link to many rows in table B.

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

What must the system remember?

Have a go

What must the system remember?

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

The data dictionary

A data dictionary has one row for each field. Everybody on the team reads the same list. Nobody guesses.

For each field it says the name, the type, the size, if it is required, and the validation rule. Read the one below for the member table. Then answer the quick check.

A data dictionary for member

FieldTypeSizeRequiredValidationKey
member_idWhole numberUp to 6 digitsYesDifferent for every memberPrimary key
nameTextUp to 40 charactersYesNot empty
yearWhole number2 digitsYesFrom 7 to 13
emailTextUp to 80 charactersNoMust contain @

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

Quick check: reading the dictionary

Have a go

Quick check: reading the dictionary

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

Many-to-many needs a link table

One student joins many clubs. One club has many students. This is many-to-many.

A database cannot store it in two tables alone. So you add a link table in the middle. Here it is membership. Each row holds one member_id and one club_id.

Now both relationships are one-to-many. One member has many memberships. One club has many memberships.

The ERD for the clubs

erDiagram
  MEMBER ||--o{ MEMBERSHIP : has
  CLUB ||--o{ MEMBERSHIP : has
  MEMBER {
    int member_id PK
    string name
    int year
  }
  CLUB {
    int club_id PK
    string club_name
  }
  MEMBERSHIP {
    int member_id FK
    int club_id FK
  }

The design as real tables

Code: sql
-- Which clubs is Aisha in?
SELECT club.club_name
FROM membership
JOIN member ON membership.member_id = member.member_id
JOIN club ON membership.club_id = club.club_id
WHERE member.name = 'Aisha';

-- Now try: INSERT INTO member VALUES (3, 'Zed', 20);
-- The validation rule refuses it.

Make a free account to save your work and track your progress.

Match each design word to its meaning

Have a go

Loading…

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

Draw the ERD for a school library

A school library lends books. A student can borrow many books over time. A book can be borrowed by many students over time. Finish the ERD. Add a link table called LOAN with a date. Mark every primary key (PK) and foreign key (FK). Show each relationship as one-to-many.

erDiagram
  STUDENT {
    int student_id PK
    string name
  }
  BOOK {
    int book_id PK
    string title
  }
  %% Add the LOAN table with its two foreign keys and a date.
  %% Add the two relationships.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Write a data dictionary for books

Write a data dictionary for the table BOOK in the library. Use a table with these columns: field, type, size, required, validation, key. Include at least five fields, such as book_id, title, author, year_published and copies. Give a sensible validation rule for each one. Say in one line why a data dictionary helps a team.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

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

Exit quiz

Have a go

Exit quiz

5 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

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.