SQL FOREIGN Vs REFERENCE KEY Constraints

The only and most crucial distinction between the two keywords "FOREIGN KEY" and "REFERENCE" is that they both make the data child data of the parent table.


SQL FOREIGN KEY Constraint

A table level limitation is created using the "FOREIGN KEY".


SQL REFERENCE KEY Constraint

Only the REFERENCE keyword can be used to create a constraint at the column level.


SQL Difference Between FOREIGN KEY And REFERENCE KEY Constraint

There are 4 main distinguish in foreign Vs reference key:-

FOREIGN KEY REFERENCE KEY
The foreign key is used to link the primary and secondary tables. A reference key is a primary key used to create column-level constraints.
It allows the database to link two tables together using a common constraint. It does not apply to the entire table.
A foreign key is a field (or set of fields) that points to another table's primary key. The foreign key's function is to ensure the data's referential integrity. To put it another way, only values that are supposed to be in the database are allowed. A reference key is a field (or set of fields) that points to a table's primary key.
The Deptno field in the EMP table is a foreign key since it refers to the Deptno in the DEPT table. The Reference key in the EMP table is the Mgr field, which points to the Empno field in the same table.