I'm trying to create a UNIQUE INDEX constraint for two columns, but only when another column contains the value 1. For example, column_1
and column_2
should be UNIQUE only when active = 1
. Any rows that contain active = 0
can share values for column_1
and column_2
with another row, regardless of what the other row's value for active
is. But rows where active = 1
cannot share values of column_1
or column_2
with another row that has active = 1
.
What I mean by "share" is two rows having the same value(s) in the same column(s). Example: row1.a = row2.a AND row1.b = row2.b. Values would be shared only if both columns in row1 matched the other two columns in row2.
I hope I made myself clear. :
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…