Locked lesson.
About this lesson
Start the process of creating a relationship between two tables by setting up a link table.
Exercise files
Download this lesson’s related exercise files.
6.02 creating-a-link-table - Exercise.docx44.1 KB 6.02 creating-a-link-table - Exercise solution.docx
134 KB TechGurusTicketing10.accdb
592 KB TechGurusTicketing10 - Complete.accdb
664 KB TripType.txt
126 B
Quick reference
Creating a Link Table
Create a link table to assist with creating relationships between tables.
When to use
We create a link table whenever we want to create a relationship between two tables that do not have common fields.
Instructions
Creating a Table
- From the Create tab, in the Tables group, select Table Design.
A new table will be created with the generic name 'Table1' and it will contain no fields. Our table needs to contain one field, 'Status'.
- Click in the FieldName field.
- Type 'Status' and press TAB.
- In the Data Type field, select Short Text.
- In the Description field, type 'Status for this ticket'.
Setting a Primary Key Field
- Click on the 'Status' field.
- From the Table Design tab, in the Tools group, click Primary Key.
Setting Field Properties
- Set the Field Size to 30.
- Set the Required field to Yes.
- Set the Allow Zero Length field to No.
- Set the Indexed field to Yes (No Duplicates).
- Click the cross to Close.
- Type a name for the table, 'tblStatus', and click OK.
Adding Records to the Table
- Double-click on 'tblStatus' to open it.
- Click in the 'Status' field and type 'Active'.
- Click in the cell below and type 'Pending'.
- Click in the cell below and type 'Closed'.
- Click in the cell below and type 'On-Hold'.
- Close all open tables.
Relationships
To create relationships between tables, we need to be able to see all tables and fields.
- From the Database Tools tab, in the Relationships group, click Relationships.
- In the Add Tables pane on the right-hand side, select both tables.
- Click Add Selected Tables.
- Drag and drop to move the tables.
Relationships can be created between tables via common fields. In our example, the two tables do not share a common field so we need to create a link table. The link table will contain a field from 'tblTicket' and a field from 'tblStatus' and we will use this table to create a relationship.
Creating a Link Table
- From the Create tab, in the Tables group, click Table.
When we select Table instead of Table Design, we automatically get an ID field in the table.
- From the Home tab, in the Views group, click View.
- Select Design View.
- Name the table 'tblTicketStatus'.
ID Field
- Click in the Description field and type 'Unique ID of this table'.
TicketID Field
- In the Field Name field, type 'TicketID'.
- In the Data Type field, choose Number.
- In the Description field, type 'Unique ID (Primary Key) of the ticket table'.
Status Field
- In the Field Name field, type 'Status'.
- In the Data Type field, choose Short Text.
- In the Description field, type 'Unique ID (Primary Key) of the status table'.
Set the field properties for the new fields.
- Go back to the Relationships tabs.
- In the Add Tables pane on the right-hand side, select 'tblTicketStatus'.
- Click Add Selected Tables.
- Position the new table in between the existing tables.
Hints & tips
- It is not always necessary to create a link table. If the tables we want to link already have common fields, a link table is not required.
Lesson notes are only available for subscribers.