I have a simple schema in which soft deletes are used (that's how it is designed and that can't be changed). There are two tables that participate in the schema: Company (id, is_deleted) and Employee (id, company_id, is_deleted) where company_id ofcourse is a FK to the Company table. The rules are:
- If a
Companyhasis_deleted = true, then allEmployeereferring to that company should haveis_deleted = true. - But an
Employeemay haveis_deleted = trueeven if the parentCompanyhasis_deleted = false.
My two problems are a) how to enforce these constraints? b) how to easiest ensure that is_deleted = true is cascaded when a Company is soft-deleted.
I added the tags postgresql and sql server because those are the databases I'm mostly interested in. If there are other solutions in other rdbms:es I'd like to hear about them too.