October 22, 2009 01:22 PM

Enforce Multitable Constraints Using Indexed Views

Indexed views work better than CHECK constraints and triggers
Rating: (0)
SQL Server Magazine
InstantDoc ID #102690
There are cases in which you need to enforce business rules between multiple tables. One such case is when validating that a custom sequence, used as a primary key in two tables, isn't used more than once. In such cases, CHECK constraints are limited to a single table. Triggers can be used but provide a non-optimal solution because you need to create a trigger on both tables. So how do you do so then? By using indexed views to implement multitable constraints.

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

Very cool.
I wrote about this exact subject a year ago.
http://dbwhisperer.blogspot.com/2008/11/adding-check-constraint-to-view.html
But the implementations were different, in my case, I didn't make use of a nums table.

mjswartd2l 11/5/2009 1:37:23 AM


You must log on before posting a comment.

Are you a new visitor? Register Here