How to set constraint sql 2 colume, Data is not available elsewhere and must be used only
The requirement.is unclear. More examples/better specification is needed..
However, i asume that after an ID is &quot; added &quot; to PI, this becomes &quot; paired&quot; and can't be paired with different ID/PI.

create a pairing table (ID,PI) with PK on Id and Unique on PI. Then add FK from your table to this new table either on (PI,ID) or an identity column

There is no simple constraint that would do what you need. What can be used is a CHECK constraint with an function that would do the check by counting ID/PI pairs with same halves. However this is not very optimal when it comes to performance