成人快手

Linked database

The way to avoid insert, delete and update anomalies is to design relational databases that use two or more linked tables to store data. In our example, it is possible to split the data into two different tables and to link them together using a field that is relevant to both tables.

The first table could store details on each member of staff. This table stores their ID, forename, surname and department ID. The ID is the primary key and is a unique value - two teachers cannot share the same ID.

Teacher Table

IDForenameSurnameDepartment ID
1ColinArthur001
2LauraBrown001
3StephenMacLeod001
4ScottSinclair002
5MichelleWie002
6RossDyett003
7IanAnderson003
8BettyFlood004
ID1
ForenameColin
SurnameArthur
Department ID001
ID2
ForenameLaura
SurnameBrown
Department ID001
ID3
ForenameStephen
SurnameMacLeod
Department ID001
ID4
ForenameScott
SurnameSinclair
Department ID002
ID5
ForenameMichelle
SurnameWie
Department ID002
ID6
ForenameRoss
SurnameDyett
Department ID003
ID7
ForenameIan
SurnameAnderson
Department ID003
ID8
ForenameBetty
SurnameFlood
Department ID004

Department Table

This table contains three fields, department ID, department and phone number. Department ID is the primary key and is unique for each department. The tables are linked together because the primary key in this table (Department ID) is also needed in the staff table 鈥 so that you know which department each member of staff is part of. In the staff table, Department ID is known as a foreign key.

Department IDDepartmentPhone number
001ICT300
002English301
003PE302
004Geography303
Department ID001
DepartmentICT
Phone number300
Department ID002
DepartmentEnglish
Phone number301
Department ID003
DepartmentPE
Phone number302
Department ID004
DepartmentGeography
Phone number303

When you use linked tables in a relational database you reduce the likelihood of insert, update and delete anomalies. In this example, moving to linked tables means:

  • A new department can be added without having to add staff information alongside it.
  • If a member of staff were deleted, such as Betty Flood, you would no longer lose the information held about her department.
  • If the ICT phone number had to change, it would only have to change once in the department table.