Consider the following scenario Suppose there are three fields in a database table
------------------------------------------
PrmiaryKey | Column A | Column B
-----------------------------------------
I need to enforce that for values in Column B should have unique values for Column A
Example
Col B Col A
12 13 (OK)
14 15 (OK)
15 16 (OK)
12 13 (OK)
15 16 (OK)
14 17 (not OK)
Since value 14 previously have value 15 under Column B. So it should not have a different value than 15. I need to enforce this behavior from database side. Is it there a particular constraint that i need to have to sort this out
Thanks in Advance.
You could try putting a
CHECK CONSTRAINT
:A constraint operates on the fields within a row. The only "constraint" that takes into account values in other rows is a unique constraint...and that really just creates an unique index. There is no way to enforce your requirement using just constraints. You have to use a trigger.