I have a table defining relationships Src smallint(5) unsigned NOT NULL, Dst smallint(5) unsigned NOT NULL, other fields I need to add a constraint that says if a given values is present in one of the columns, then. 1) Cannot be duplicated in the same column. 2) Cannot be duplicated in the other column either. This is invalid src dst 1 354 666 1 Since the value 1 is present in the first row, it cannot be present in the second row. How can I define this type of constraint? I'm doing a lightweight check at application lever. But I want the DB to ensure it.