What is difference between foreign key and reference key?

I am supposing that you are talking about using the REFERENCES where the FOREIGN KEY keyword is not used when constraining a column inline, which is called a column-level foreign key constraint, eg.

author_id INTEGER REFERENCES author(id)

… instead of the table-level foreign key constraint, which is placed after the column declarations …

author_id INTEGER,
FOREIGN KEY(author_id) REFERENCES author(id)

The answer is, that it is simply shorthand syntax for the same thing. The main concern when altering between the two should be readability.

For more advanced use, it might be relevant that only table-level foreign key constraints can describe constraints on multiple keys at once, where all must be present in the referenced table.


Do note that MySQLparses but ignores “inline REFERENCES specifications” (as defined in the SQL standard) where the references are defined as part of the column specification’, meaning that only the table-level foreign key constraint will work.

Both Postgres and Microsoft’s SQL Server respect both column- and table-level foreign key constraints.

Leave a Comment