I have some related tables:
Application
- stores a list of applicationsApplicationInstall
- for each application, multiple installations are present (I have a foreign key ApplicationUid
)SecurityPrincipal
- for each ApplicationInstall
I have many principals (I have a foreign key ApplicationInstallUid
).
I have also a table SecurityPrincipalType
, linked to Application
through a 1-to-many.
I would like to have a rule that guarantees that when I insert a record in SecurityPrincipal
its Type comes from a SecurityPrincipalType
linked to the correct Application
.
I didn't rename the tables because I usually prefer to have names to think about. But I think the following scenario is equivalent:
Table A
n..1 Table B
1..n Table C
And I want to enforce that a column in C
contains only values coming from A
, but linked via B
.
I'm considering:
- triggers
- foreign keys?
- application level checks (but I would prefer to have some check at the db level)
What should I do?