FK refers to primary key and Primary key can't be null.
Primary key value never can be NULL, that's correct.
But a foreign key column can be NULL(able), it then references no PK and that's completley valid.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
According to me, FKs can't be null as otherwise It will violate the Foreign Key constraint.
FK refers to primary key and Primary key can't be null.
Can you help me understand this better?
FK refers to primary key and Primary key can't be null.
Primary key value never can be NULL, that's correct.
But a foreign key column can be NULL(able), it then references no PK and that's completley valid.
It will violate the Foreign Key constraint.
Primary Key Constraints and Foreign Key Constraints are two different things. Foreign key simply requires that the value in that field must exist first in a different table (the parent table).
NULL by definition is not a value. Null means that we do not yet know what the value is.
Here is a simple example: Suppose we have an employee table with employee_id
and manager_id
where manager_id
is foreign key and CEO of the organization doesn't have manager so his manager_id
will be NULL in Employee table.
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.