Foreign key

Updated: 10/02/2017 by Computer Hope
foreign key

In an SQL (Structured Query Language) database, a foreign key is a column or set of columns that link its table and another table. The main table the link is created from contains a primary key, which links to the foreign key of the second table. This primary key > foreign key link allows one or more rows of data in one table to link or relate to one or more rows of data in another table.

A foreign key is created using the "FOREIGN KEY" constraint when either creating a new database table or altering an existing database table. The column designated as a foreign key also inherently has the "NOT NULL" constraint, which means it must contain a value and cannot be blank.

Tip

Columns designated as a foreign key can have a separate index created for them, which improves the speed at which searches can be made in the database.

Database, Database terms, Primary key, Programming terms, Software terms