Primary & Foreign Keys

Level – National 5+

Primary Key

Every table should have a primary key – a unique identifier for each record.

Primary keys are required (Not Null), and must be unique

  • Right-click on the Table name
  • Select “Modify table”
  • Tick the NN, PK and U options for the primary key

Foreign Key

A foreign key connects each record in a table to a record in another table. The other table must be created before the tables can be linked.
eg Each record in “appointments” table will link to a customer. The customers table must be created before the appointments table.

  • Right-click on the Table that has the foreign key
  • Select “Modify table”
  • Widen the table so you can see the Foreign Key column
  • Double-click where the foreign key row and the Foreign Key column cross:
  • Use the drop-down menus to select the other table, and its primary key:
  • Click inside the grey “Foreign key clauses…” box, and press the Enter key
  • Check the code in the bottom panel, and press the OK button