Why can't I ...
... set up a foreign key relationship in SQL Server 2008 where the parent is a view with a unique index set up over it?
Unless I'm much mistaken, you can't do this.
You can achieve the same result with triggers, but:
Unless I'm much mistaken, you can't do this.
You can achieve the same result with triggers, but:
- A lot of people hate triggers;
- You have to code the things, which introduces possible errors, depending on how sharp the coder is and how well he or she knows trigger behavior. Foreign key relationships are hard to get wrong.
- ETA: You also have to set up triggers on both sides of the relationship, if you want to constrain both tables. With a foreign key, the mutual constraining is automatic.
2 Comments:
Without knowing the details, methinks a different db design would yield the functionality you desire.
That said ... you question is a good one.
I can think of designs that would make the functionality I want possible, but it's a bit like stretching a too-small sheet over a too-large mattress: if you get the final corner covered, it's only because some other corner has come untucked. I could achieve true referential integrity with some of the ideas I've come up with, but only at the cost of adding complexity in even less welcome places.
I think the trigger is probably my best bet, given the size and maturity of this system. The impact (both on the system and in developer/QA hours) is probably the smallest with that option.
Thanks!
Post a Comment
<< Home