Types of Relationships
Data is shared between different tables using a Relationship.
Relationships can be created between two tables using the Primary Key and Foreign Key fields.
In our example, the customer table has a Primary Key called CustomerID.
The orders table has a Foreign Key also called CustomerID.
We created a relationship between these two fields so the CustomerID number from the customer table can be shared with the CustomerID field in the Orders table.
We did the same between the Orders table and the Products table. The Products table has a Primary Key called ProductID. The Orders table has a Foreign Key also called ProductID.
We created a relationship between these two fields so the ProductID number from the product table can be shared with the ProductID field in the orders table.
There are three types of relationships we can create in a database.
|One to One||Where both tables only have one record|
|One to Many||Where the table with the primary key has only one record that relates to many records in the other table|
|Many to Many||Where each record in the primary key table relates to many records in the other table|
Print out this Page