A primary-key field and a foreign-key field don't need to have the same name to be linkable.
They do need to contain the same data. Remember, the RDBMS doesn't identify the link between the tables, the designer does.
The next lesson describes referential integrity.
| Lesson 14 | Database Foreign keys |
| Objective | Define foreign keys for Relational Database. |
When you create a database to manage information for a business, it is common for tables in the database to have columns in common.
In the following illustration, the CUSTOMER and ORDER tables share the CustID column.
In the following illustration, the CUSTOMER and ORDER tables share the CustID column.
The difference between the CustID field in the CUSTOMER table and its counterpart in the ORDER table is that the CustID field is the
primary-key field for the CUSTOMER table but not for the ORDER table. When table A contains a field that is the primary-key field in table
B, that field in table A is referred to as a foreign key .
Foreign key: A field (or combination of fields) used to link tables; a corresponding primary key field occurs in the same database.
Foreign Key - Primary Key
Foreign key: A field (or combination of fields) used to link tables; a corresponding primary key field occurs in the same database.
A foreign key field can be identified with the primary key of more than one table.
This is not a requirement.
Benefits of Foreign Keys
This is not a requirement.
While foreign keys don't uniquely identify records in their tables, they do provide an important benefit. They enable you to create
links between tables that share fields. Again, consider the CUSTOMER and ORDER tables.
Primary Key Field Relational Constructs - Quiz
Before you move on to the next lesson, click the Quiz link below to reinforce your understanding of foreign keys.
Relational Constructs - Quiz
Relational Constructs - Quiz