Customers
customer_id
Orders
order_id
customer_id fk
If I have two tables and define a foreign key on customer_id in the Orders table, by allowing it to be null I am saying that I can have an order that does not have a customer associated with it. As such, the notion of a nullable foreign key seems at odds with the purpose of a foreign key, which is to enforce this constraint.
Is there a simple example of a situation in which a nullable foreign key would be necessary? Or an argument in favor of permitting them?
To set a foreign key nullable or null use below sql script
The purpose of a foreign key is the make explicit the concept the random integer in the Orders table actually refers to an item in the Customers table. Actually enforcing that as a constraint is incidental.