Keys

Visual Database Tools

Visual Database Tools

Keys

There are two kinds of keys.  A primary key is a set of columns from a table that are guaranteed to have unique values for each row of that table.  A primary key is also called a primary key constraint, because it effectively constrains the values you can add to the table: it prevents you from adding a row to the table whose primary key columns are all equal to the corresponding values of some other row in that table.

A foreign key is a correspondence between a set of columns in one table and the set of primary key columns in some other table.  When discussing foreign keys, the two participating tables are sometimes called the foreign-key table and the primary-key table.  A foreign key is also called a foreign key constraint because it constrains table rows: it ensures that any row you add to the foreign-key table has a corresponding row in the primary-key table.  That is, it requires that any row added to the foreign-key table have values in the foreign-key column that correspond to the respective values of the primary key columns for some row in the primary-key table.

For more information about primary keys, see Primary Key Constraints.  For more information about foreign keys, see Foreign Key Constraints.  For details about working with keys, see Working with Keys.