Quantcast
Channel: Active questions tagged referential-integrity - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 60

SQL Server - ensuring a complex relation on insert

$
0
0

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?


Viewing all articles
Browse latest Browse all 60

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>