Table relationships connect two or more tables using related fields. They help organize data, reduce unnecessary duplication, and allow Microsoft Access to retrieve related information from multiple tables.
A table relationship is a connection between tables based on related fields. For example, a Students table can be connected to a Courses table using a CourseID field.
| StudentID | StudentName | CourseID |
|---|---|---|
| 101 | Amit | 1 |
| 102 | Priya | 2 |
| 103 | Rahul | 1 |
| CourseID | CourseName | CourseFees |
|---|---|---|
| 1 | ADCA | 10000 |
| 2 | Tally Prime | 4000 |
The CourseID field connects the Students table to the Courses table. Students with CourseID 1 are associated with the ADCA course.
For example, if the ADCA course fee changes, you can update the fee in the Courses table instead of updating multiple student records.
A primary key uniquely identifies each record in a table. It cannot contain duplicate values or Null values.
Example: StudentID in the Students table.
A foreign key is a field that refers to the primary key in another table. It connects related records between tables.
Example: CourseID in the Students table refers to CourseID in the Courses table.
| Field | Table | Key Type |
|---|---|---|
| CourseID | Courses | Primary Key |
| CourseID | Students | Foreign Key |
| StudentID | Students | Primary Key |
In a one-to-one relationship, each record in one table corresponds to at most one record in the other table, and vice versa.
Example: An Employees table connected to an EmployeeDetails table containing one separate detail record per employee.
In a one-to-many relationship, one record in the first table can be related to multiple records in the second table.
Example: One course can be associated with many students, while each student record refers to one course.
In a many-to-many relationship, multiple records in one table can be related to multiple records in another table. A junction table is normally used to implement it.
Example: Students can enroll in multiple courses, and each course can have multiple students.
| Relationship | Example |
|---|---|
| One-to-One | Employee and EmployeeDetails |
| One-to-Many | One course and many students |
| Many-to-Many | Many students and many courses |
Follow these steps to create a relationship between two tables:
Referential integrity helps ensure that foreign-key values refer to existing records in the related table.
For example, if CourseID 1 exists in the Courses table, a student can refer to CourseID 1 in the Students table. If referential integrity is enforced, Access normally prevents entering a non-Null foreign-key value that has no matching parent record.
Create the following two tables.
Goal: Understand how related tables work and how Access connects their records.
1. What is the purpose of a table relationship?
2. Which key refers to a key in another table?
3. Which relationship allows one course to have many students?