This is probably a trivial question, but I'm still a little clumsy when it comes to foreign key constraints so I wanted to make sure.
Let's say I have a table countries
with the fields country_id
(PK) and name
, and a table cities
with the fields city_id
(PK), name
and country_id
(FK).
The foreign key cities.country_id
has the constraint ON DELETE SET NULL
. As I understand it, this means that if a record from countries
is deleted, any records in cities
that reference that deleted record's country_id
will have its country_id
field set to NULL.
What if, however, cities.country_id
has the attribute NOT NULL
? Will this prevent the foreign key constraint from working properly? It would make sense that it does, but I just want to check.