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

Preview

Data models and E-R diagrams

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

45 minutes

Who has the book?

A school library has 5,000 books and 800 students. Aisha borrows two books. Sam borrows one.

How can the library know who has which book, and when it is due back?

First you decide what data you need and how the parts connect. You draw it. This drawing is a data model.

Key words

WordWhat it meansExample
DatabaseAn organised store of data that programs can search and change.
Data modelA picture of the data you need and how it is organised.
EntityA thing you keep data about.Student, Book
AttributeOne fact about an entity.name, title
RelationshipA link between two entities.A student borrows a book
Primary keyA value that is different for every row. It finds one row.student_id
Foreign keyA column that holds the primary key of another table.loan.student_id
Data typeThe kind of value a column holds, such as whole numbers or text.
IntegerA whole number with no decimal point.42
IndexA list that helps the database find rows fast.
Hierarchical modelData organised as a tree. Each item has one parent.
Relational modelData in tables that are linked by keys.
E-R modelEntity Relationship model. A diagram of entities and their links.
UMLUnified Modelling Language. A standard way to draw designs, including classes.

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

Why draw before you build?

A building needs a plan before the work starts. Data is the same.

If you find a mistake in a drawing, you change the drawing. If you find a mistake after you built the database, you must change the data too. That costs a lot more.

A data model shows the data you need and how it is organised.

Quick check: entity or attribute?

Have a go

Quick check: entity or attribute?

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.

How to read an E-R diagram

Each box is an entity. Each line is a relationship.

The marks at the end of a line say how many. || means exactly one. o{ means zero or many.

In the diagrams below, one student makes zero or many loans. One book is in zero or many loans. This is a one-to-many relationship. The loan table holds both foreign keys.

Three levels of data model

LevelWho it is forWhat it showsLibrary example
ConceptualCustomers and managersThe big picture: entities and relationships. No detail.Student borrows Book
LogicalDesignersTables, attributes and keys. Not tied to one database product.Student(student_id, name, year)
PhysicalDevelopersThe real design for one database: data types, sizes, indexes.student_id INTEGER PRIMARY KEY

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

Read the big picture

Have a go

Read the big picture

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

9 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.