Let’s say I have a table parent with primary key id, and a table child with foreign key parent_id and a “boolean” column (constrained to a 0 or 1), let’s call it is_initial.
What I want to do is put a constraint on child so that for a particular value of parent_id, there can be only one row with is_initial = 1. There can be any number of rows with is_initial = 0.
Can this be done with a constraint? I prefer not to add a trigger.
Thanks.
Here you go, I believe I understand what you are looking for now
Note the change in the unique index:
Ammended Code
Here are the results: