Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
If I understand your question correctly, i.e. Is it possible to enforce that constraint at the database level? Then the short answer is: No. In the business logic for the program, every re...
Answer
#1: Initial revision
If I understand your question correctly, i.e. > Is it possible to enforce that constraint ***at the database level***? Then the short answer is: No. > In the business logic for the program, every record in the A table must have a relationship to at least one record in the B table Since you already a `M:M` relation between tables A and B through an associative table C, you can only require that an entry in C already has valid PKs in tables A and B. However, there's no way (AFAIK) to cause entry in A to depend on an entry in B or vice versa , **unless** the relation between A and B is set to be 1:M. In other words, you'd have to go from: ``` +---+ +---+ +---+ | A |1----*| C |*----1| B | +---+ +---+ +---+ ``` to something like: ``` +---+ +---+ | A |*-----1..*| B | +---+ +---+ ``` where `*` by itself means "0 or more" and `1..*` means "1 or more". If you want the above, but without changing the original M:M relation, you may need to look at either using database triggers (what I'd look into first) or implementing it in the actual application code (which I'd try to avoid). If there's no choice but to write it in the application layer code, I'd at least put it in a library/module that can be easily reused across the entire application, to prevent this implementation issue from propagating uncontrollably; it is technical debt.