Draw it before you build it
A builder draws a plan before the first brick. A programmer draws the data before the first line of code.
A good drawing lets a team agree in five minutes. Without it, they talk for an hour and still disagree.
Today you draw all three data models.
Key words
| Word | What it means | Example |
|---|---|---|
| Block | A box in a drawing that shows one item. | A box with Park in it |
| Arrow | A line with a point that joins two blocks. | Station to Park |
| Label | Words that say what a block or arrow is. | 5 min |
| Parent | The block an arrow comes from, above its child. | Head teacher |
| Child | The block that an arrow points to. | Head of Science |
| Hierarchical model | A tree where every item has one parent. | Folders |
| Network model | A web where an item can have many parents. | Bus routes |
| Relational model | Tables linked by keys. | Clubs and members |
| Key | A column that links a row to a row in another table. | club_id |
| Row | One record in a table. | 1, Sam, 1 |
| Column | One kind of fact in a table. | name |
The cells students fill in are left blank in this preview.
A hierarchical model, drawn
Quick check: read the drawing
Have a go
Quick check: read the drawing
3 questionsRules for trees and webs
Draw one block for each item. Draw an arrow for each link. Put a label on a block to name it. Put a label on an arrow to say what the link means.
In a tree, arrows go from parent to child, and each block gets one arrow in. In a network, a block can get many arrows in. In the bus map below, a bus goes from the start of an arrow to its point. School gets two arrows in.
A network model, drawn
Draw a tree
Complete the tree of a school. Under Head of Science add two teachers. Under Head of English add two teachers. Give every arrow the label manages. Give every block a name. The first lines are done for you.
flowchart TD
head[Head teacher] -->|manages| sci[Head of Science]
head -->|manages| eng[Head of English]
%% add the teachers below
Make a free account to save your work, or press Start lab to work through the whole lesson.
Draw a network
Draw the bus stops of a town as a network. The stops are Station, Park, School and Mall. A bus goes from Station to Park in 5 minutes. A bus goes from Park to School in 4 minutes. A bus goes from School to Mall in 6 minutes. A bus goes from Station to School in 10 minutes. Draw every link as an arrow and write its time on it. Which stop gets two arrows in?
flowchart LR
station[Station] -->|5 min| park[Park]
%% add the other three arrows below
Make a free account to save your work, or press Start lab to work through the whole lesson.
Rules for tables
You draw a relational model as tables. Write the name of the table on top. Put the columns across the top row. Put each record in one row below.
Mark the key column. It links a row to a row in the other table. Look at the two tables below. In the members table, club_id 1 points to Chess.
The clubs table
| clubs.id | clubs.name |
|---|---|
| 1 | Chess |
| 2 | Music |
The cells students fill in are left blank in this preview.
The members table
| members.id | members.name | members.club_id (key) |
|---|---|---|
| 1 | Sam | 1 |
| 2 | Aisha | 2 |
| 3 | Leo | 1 |
The cells students fill in are left blank in this preview.
Match the part of the drawing
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Watch: drawing data models
Press Play on the short film below. It shows the three parts of a drawing, then a tree, a network and two tables.
Film: drawing data models
Drawing data models
Every scene, as text
- Draw it before you build it. A builder draws a plan before the first brick. A programmer draws the data before the first line of code. A good drawing lets a team agree in five minutes (good: a drawing first). Without it, they talk for an hour and still disagree (bad: no drawing).
- Rules for trees and webs. Station, with an arrow to Park and 5 min on the arrow (Park: a block, one item; Station to Park: an arrow; 5 min: a label on the arrow). Put a label on an arrow to say what the link means.
- A hierarchical model, drawn. Head teacher, with arrows down to Head of Science and Head of English; Head of Science, with an arrow down to Mr Khan; Head of English, with an arrow down to Ms Evans; every arrow labelled manages (Head teacher: the parent; Head of English: a child; manages: what each link means). An arrow comes from a parent and points to its child.
- Myth (false): a block in a tree can have two parents. That is not true: each block in a tree gets one arrow in. In a network, a block can get many arrows in. A bus map: Station to Park, 5 min; Station to School, 10 min; Park to School, 4 min; Park to Mall, 8 min (bus routes: a network model; School: two arrows in).
- Rules for tables. The clubs table: id, name; 1, Chess; 2, Music (clubs: the table's name, on top; id, name: the columns, top row). The members table: id, name, club_id (key); 1, Sam, 1; 2, Aisha, 2; 3, Leo, 1 (club_id: the key column, marked; 1, Sam, 1: one row, one record), with an arrow from Sam's club_id to Chess.
Extra: The same tables as an ER picture
Extra: Try it: build the tables in SQL
-- PRIMARY KEY (PK): a column with a different value in every row.
-- FOREIGN KEY (FK): a column that holds the primary key of a row in another table.
CREATE TABLE clubs (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE members (id INTEGER PRIMARY KEY, name TEXT, club_id INTEGER,
FOREIGN KEY (club_id) REFERENCES clubs(id));
INSERT INTO clubs VALUES (1, 'Chess');
INSERT INTO members VALUES (1, 'Sam', 1);
SELECT * FROM members;
-- Add one more club and one more member, then run it again.
Draw the tables
A library has books and authors. One author writes many books. A book has one author. Draw the two tables. Write the name of each table, then its columns, then two rows of example data. The authors table has id and name. The books table has id, title and author_id. Mark author_id as the key column and say which table it points to.
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.
Your turn: tables from a picture
Have a go
Your turn: tables from a picture
4 questionsFinal check
Have a go
Final check
5 questionsRemember
Important
Tree and network: blocks, arrows and labels. Relational: tables, rows, columns and labels. Always mark the key column and say what each link means.