A-Level Computer Science / Unit 8: Relational Databases and SQL

8.1.2 Relational Terminology, Keys and Indexes

πŸ”’ Lesson slides are available to signed-in users. Sign in

8.1.2 Relational Terminology, Keys and Indexes

A table has records (rows) and fields (columns). Keys identify records or link tables. An index helps the DBMS find or order records more efficiently.

By the end of this page, you should be able to:

  • define and use the key terms accurately;
  • explain how the idea works using a new example;
  • apply the idea to a database design or SQL task.

1. Name the parts precisely

An entity is a type of thing about which a database stores information, such as Equipment. A table stores records about that entity. Each record (also called a row or tuple) describes one item. Each field (column or attribute) stores one property, such as EquipmentName.

2. Choose a primary key

A primary key is a field, or combination of fields, that uniquely identifies each record. A key should have a value for every record and must not be shared between records. EquipmentID is usually safer than EquipmentName because two items might have the same name.

3. Candidate keys and secondary keys

A candidate key is a field or field combination that could uniquely identify records and could be selected as the primary key. A secondary key is useful for searching or sorting but does not have to be unique. For example, Category may help find equipment, even if many items share a category.

4. An index is a search aid

An index is an additional structure based on one or more fields. It helps the DBMS locate or return records in a useful order without checking every row in sequence. An index can make searches faster, but it uses storage and must be maintained when records change.

Worked example

Suppose the table Equipment has EquipmentID, EquipmentName and Category. EquipmentID can be the primary key; EquipmentName might be a candidate key only if names are guaranteed unique; Category could be a secondary search field.

Common mistake to avoid

A field used to search is not automatically a candidate key. It is a candidate key only if it uniquely identifies every record under the database rules.

Interactive check

Choose an answer, read the explanation, and continue to the next example.

Try it

Check your understanding

Question 1 of 3
Score: 0 / 3

Independent practice

Try this original question before opening the suggested response.

A museum stores Exhibit(ExhibitCode, Title, RoomNumber). Identify one suitable primary key, one possible secondary key and one reason an index on RoomNumber may help. (3)

Suggested response

ExhibitCode is a suitable primary key if every exhibit has a unique code. RoomNumber can be a secondary search field because many exhibits may share a room. An index on RoomNumber can help retrieve exhibits in a chosen room more quickly.

Answering clearly

Use the technical term, state what it does, and connect your explanation to the details in the question.