• domingo.sqlservercentral (4/20/2015)


    I found examples for many columns, as below:

    CONSTRAINT chk_Person CHECK (P_Id>0 AND City='Sandnes')

    but... it works independly for these columns, as two simple check constraints. I need a rule for relationship beetween few columns values. And refusing only when inserting/updating row with SOME 'a' value in 1st column and SOME 'b' value in the 2nd (only when both conditions are true).

    Your best bet would probably be to post DDL for your example table, along with some INSERT or UPDATE statements that should both be allowed and be blocked. With a clear explanation of why each should be allowed or blocked.

    This approach will be the fastest way to get a tested, working solution to your situation.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St