質問

Is it possible to make a 2 coulmns unique in mysql db? for example:

ID | columnA | columnB
 1 | Dan     | 1
 2 | Dan     | 2
 3 | Zak     | 1
 4 | Dan     | 1 (WHEN TRYING TO INSERT ROW 4 - NOT ALLOWED! DUPLICATE COULMNA + COLUMNB)
役に立ちましたか?

解決

Try this:

ALTER TABLE tableA ADD UNIQUE INDEX idxColAB (columnA, columnB)

他のヒント

A unique index guarantees that the index key contains no duplicate values and therefore every row in the table is in some way unique. There are no significant differences between creating a UNIQUE constraint and creating a unique index that is independent of a constraint. Data validation occurs in the same manner, and the query optimizer does not differentiate between a unique index created by a constraint or manually created. However, creating a UNIQUE constraint on the column makes the objective of the index clear

link

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top