What is a foreign key ?

obs

Registered User.
Local time
Yesterday, 18:30
Joined
Mar 1, 2007
Messages
25
Hi all,
my question is what is a foreign key and how is it used ?
 
A Foreign key is a primary key from a Foreign table. It is used to relate records to each other from different tables.
 
so, the FK in a table should contain values from the linked table (the exact values), right ?
Does it have to contain values of the primary key ?
 
say u have 2 tables
table1
table2
table1
table1ID <PK
table2ID <FK

Table2
table2ID <PK

a setup like that is how a foreign key is used
 
Just to put it in proper perspective for those reading this thread and not understanding all of the answer...

In a table, the primary key (PK) is used to find records. It must be unique.

In a table, a foreign key is VERY OFTEN part of a relationship with another (different) table. A foreign key is used to find the matching record in that other table. You store the other record's PK in this table's FK field.

A foreign key is VERY OFTEN on the "many" side of a one//many relationship, and the key on the "one" side of that same relationship is usually the PK of the corresponding table. Therefore, while a PK absolutely MUST be unique, an FK might not be unique.

I said "VERY OFTEN" above because sometimes the FK isn't necessarily a participant in a formal Access relationship as displayed in the Relationships Window. But it is ALWAYS an indicator of the location of something else related to the current table.

One last thing: You can only have one PK in a table. You can, however, have many different FKs in the same table, one for each actual or implied relationship with another data source.
 

Users who are viewing this thread

Back
Top Bottom