Say I have the following ER diagram:
Enforcing the mandatory participation constraint at the one end is easy, I simply make the foreign key (school_id
) in Student
NOT NULL
.
But how can I enforce the mandatory participation constraint at the many end (each School
must at least have one Student
), that is, how can I prevent something like this:
If I inserted a School
row first, it will obviously have no Students
.
And I also can't insert a Student
row first with a school_id
that doesn't exist in the School
table (referential integrity constraint will prevent it) and then insert a School
row (with the same school_id
).
Note: I am using MySQL.