Computer ScienceCore20 min read

Database Design Process

From a description in words to a set of tables that will not fight you later

This topic appears in:

01

Design happens before any software is opened

The temptation is to open Access and start making tables. The resulting database usually works for a month and then becomes impossible to change, because decisions were made by accident rather than on purpose.

Design proceeds in three stages, and only the last involves a particular product.

StageProducesDepends on the software?
Conceptual designentities, attributes and relationships — an ER diagramno
Logical designtables, fields, keys, and normalised structureno
Physical designdata types, indexes, storage and access pathsyes

Why the first two stages are product-independent

A conceptual and logical design that mentions no product can be implemented in Access, MySQL, Oracle or a spreadsheet, and can be reviewed by someone who knows the school but not the software. That separation is the point: the person who understands the problem and the person who understands the tool are rarely the same person.

02

Finding the entities and attributes

Start from a written description of what the system must do, and read it grammatically. The nouns are candidate entities and attributes; the verbs connecting them are candidate relationships.

Then sort the nouns. A noun with several properties of its own is an entity and becomes a table. A noun that is simply a property of something else is an attribute and becomes a field. "Student" has a name, an address and a date of birth, so it is an entity. "Address" has no properties of its own here, so it is an attribute of Student — though in a delivery company, where an address has a district, a postcode and access instructions, it might well become an entity.

Worked example

Design a database from this description: "A clinic records patients and their appointments. Each appointment is with one doctor, at a stated date and time. A patient may have many appointments and a doctor sees many patients."

  1. Nouns: clinic, patient, appointment, doctor, date, time.Underline them in the question paper before doing anything else.
  2. Clinic is the system itself, not an entity. Date and time are properties of an appointment, so they are attributes.Discarding non-entities early keeps the design small.
  3. Entities: PATIENT, DOCTOR, APPOINTMENT — each has properties of its own.APPOINTMENT is an entity in its own right because it has a date and a time.
  4. Relationships: PATIENT has many APPOINTMENTs; DOCTOR has many APPOINTMENTs.The apparent many-to-many between patient and doctor is resolved by APPOINTMENT, which sits between them.
  5. PATIENT(PatientID, Name, Phone), DOCTOR(DoctorID, Name, Specialism), APPOINTMENT(ApptID, PatientID, DoctorID, Date, Time).Date and Time belong to the appointment, since they describe that meeting rather than either person.

Three tables, with APPOINTMENT holding both foreign keys plus the date and time.

The clinic above is the Many to many case already resolved: patient and doctor are many-to-many, and APPOINTMENT is the linking table that makes it storable.

03

Drawing the ER diagram

An entity-relationship diagram is the conceptual design on one page. Entities are rectangles, relationships are diamonds or labelled lines between them, and attributes are ovals or simply listed inside the entity box.

The cardinality — 1:1, 1:M or M:N — is written at each end, and it is the part that actually determines the tables. Getting it wrong produces a design that cannot store the data at all, which is why it is worth stating both directions in words before writing a symbol: "one class has many students; one student has one class."

Say it both ways round

Students decide a relationship is one-to-many after checking only one direction. Test both: "one doctor has many appointments" and "one appointment has one doctor" gives 1:M. But "one student takes many subjects" and "one subject has many students" gives M:N — and that needs a third table. Checking one direction cannot tell the two cases apart.

04

From diagram to tables

Converting a finished ER diagram is mechanical, which is the reward for doing the design properly.

Every entity becomes a table, with its attributes as fields and a primary key chosen or invented. Every 1:M relationship becomes a foreign key on the "many" side. Every M:N relationship becomes a new linking table containing both primary keys, plus any attribute belonging to the relationship itself. A 1:1 relationship becomes a foreign key on either side — or, more often, a reason to ask whether the two entities should be one table.

Before you leave this chapter

  1. Conceptual and logical design mention no product; only physical design does.
  2. Nouns are candidate entities and attributes; verbs are candidate relationships.
  3. A noun with properties of its own is an entity; otherwise it is an attribute.
  4. State every relationship in both directions before deciding its cardinality.
  5. Entity → table, 1:M → foreign key on the many side, M:N → a linking table.
05

Checking a design before building it

A design that looks reasonable can still be unable to store the data it was made for. Four questions catch almost every fault, and all of them can be answered on paper in a few minutes — which is considerably cheaper than discovering the problem after the forms and reports have been built on top of it.

  • Can every fact be stored exactly once? If something has to be typed into two tables, the design has a redundancy that will become an inconsistency.
  • Can every question be answered? Walk through each report the system must produce and check the data it needs actually exists somewhere.
  • Does every table have a primary key that will never change? A key built from a name or a phone number is a problem waiting for someone to get married or move house.
  • Is every M:N relationship resolved? An unresolved one cannot be stored at all, and it is the fault most often missed.

Test the design with real examples

Take three or four genuine records and write them into your tables by hand. A student in two classes, a book with two authors, an order with three items — the awkward cases are where designs break. If you cannot write the example down, the design is wrong, and you have found out before writing any software.

Practice questions

6 questions · 20 marks · full working on every one

Try each one on paper first, then open the working. The marks are shown where they are actually awarded, because that is where they are actually lost.

Short questions

3 · 6 marks

Two marks each, in the style of the short-question section of the paper. Answer in two or three lines.

SQ1[2 marks]
Name the three stages of database design.
Model answer

Conceptual design — identifying entities, attributes and relationships. Logical design — converting these to tables with keys and normalising them. Physical design — choosing data types, indexes and storage for the particular DBMS.

Examiner tip. Only the physical stage depends on the software chosen, which is worth stating as it shows why the stages are separated.

SQ2[2 marks]
How do you decide whether a noun in a description is an entity or an attribute?
Model answer

A noun with properties of its own that must be stored is an entity and becomes a table. A noun that is simply a single property of something else is an attribute and becomes a field. "Address" is usually an attribute of a customer, but becomes an entity if the system must store a district, postcode and access notes for each one.

Examiner tip. The example showing the same noun going either way, depending on the system, is what demonstrates understanding here.

SQ3[2 marks]
What does cardinality mean in an ER diagram?
Model answer

The number of records on each side of a relationship that may be associated with one record on the other — written 1:1, 1:M or M:N. It determines the table structure, since a 1:M becomes a foreign key while an M:N requires an additional linking table.

Examiner tip. Saying what it determines is worth the second mark. Cardinality is not a label on the diagram; it dictates the design.

Solved numericals

2 · 8 marks

Full working, one step per line, with the marks shown where they are awarded.

N1[4 marks]
From this description, identify the entities and the relationship: "A bookshop stocks many titles. Each title is supplied by one publisher, and a publisher supplies many titles."
Full working
  1. Entities: TITLE and PUBLISHERbookshop is the system, not an entity[1]
  2. Relationship: one publisher supplies many titles, and each title has one publisher — 1:Mstated in both directions[1]
  3. PUBLISHER(PublisherID, Name, Address)[1]
  4. TITLE(ISBN, Title, Price, PublisherID) — the foreign key on the many sideISBN is a natural primary key here[1]

TITLE and PUBLISHER, in a 1:M relationship, with PublisherID as a foreign key in TITLE.

Examiner tip. ISBN is one of the rare cases where a meaningful value is a good primary key: it is globally unique and never changes for a given edition.

N2[4 marks]
Explain why an M:N relationship cannot be implemented with two tables, and describe how it is resolved.
Full working
  1. A field holds a single value, so it cannot store a list of related recordsthe fundamental reason[1]
  2. Putting a foreign key on either side would allow only one match, which contradicts "many"[1]
  3. A third linking table is created, containing the primary keys of both entities as foreign keys[1]
  4. This converts the M:N into two 1:M relationships, each of which tables can express; the linking table also holds any attribute of the relationship itself[1]

A field holds one value, so a linking table with both foreign keys is required, giving two 1:M relationships.

Examiner tip. The reason — one field, one value — is the mark. Describing the solution without it is only half the answer.

Long questions

1 · 6 marks

Theory and numerical together, as they appear in the long-question section.

LQ1[6 marks]
A gym records members, the classes it runs, and which members attend which classes. Each class is taught by one instructor.
  1. Identify the entities.
  2. State each relationship with its cardinality.
  3. Give the tables with their primary and foreign keys.
Mark scheme
  1. Entities: MEMBER, CLASS, INSTRUCTORgym is the system itself[1]
  2. INSTRUCTOR to CLASS is 1:M — one instructor teaches many classes, each class has one instructor[1]
  3. MEMBER to CLASS is M:N — a member attends many classes and a class has many membersstated in both directions[1]
  4. INSTRUCTOR(InstructorID, Name) and CLASS(ClassID, ClassName, Time, InstructorID)InstructorID is the foreign key on the many side[1]
  5. MEMBER(MemberID, Name, JoinDate)[1]
  6. ATTENDANCE(MemberID, ClassID, Date) — a linking table with a composite key, resolving the M:NDate belongs here, being a property of that attendance[1]

(a) MEMBER, CLASS, INSTRUCTOR (b) instructor–class 1:M, member–class M:N (c) four tables, with ATTENDANCE linking members to classes

Examiner tip. Four entities named in the question produce three tables plus one linking table. If your answer has only as many tables as entities, check whether you missed an M:N.