Foreign keys are a data integrity feature of relational (and SQL) databases. A foreign key is a set of attributes in a relational table that is subject to a referential integrity constraint. The referential integrity constraint mandates that the values of the foreign key attributes in one table, A, must match with corresponding values in some specified table B (which may sometimes be the same table as A).
The foreign key identifies a column or set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. The columns in the referencing table must reference the columns of the primary key or other superkey in the referenced table. The values in one row of the referencing columns must occur in a single row in the referenced table.
Thus, a row in the referencing table cannot contain values that don't exist in the referenced table (except potentially NULL). This way references can be made to link information together and it is an essential part of database normalization.
Multiple rows in the referencing table may refer to the same row in the referenced table. Most of the time, it reflects the one (parent table or referenced table) to many (child table, or referencing table) relationship.
Composite foreign key consists of two or more columns. All the columns that form a single foreign key reference one table.
In some cases foreign key constraint can reference the same table. For example for employee table, having employee_number, employee_name, and manager_employee_number. Every manager is also an employee, so it can be built a foreign key constraints between manager_employee_number to the employee_number
Reference