sql unique constraint on a 2 columns combination
问题 How can you create a unique constraint on a combination of two values in two columns. meaning column1 column2 2 1 looking for the constraint to disallow column1 column2 1 2 回答1: If your database allows expressions in an index you can do something like this (ANSI SQL): CREATE UNIQUE INDEX on your_table (least(column1, column2) , greatest(column1, column2)); Note this is a unique index not a unique constraint. The only difference for most DBMS is that you can't have a unique index as the target