Creating UNIQUE constraint on multiple columns in MySQL Workbench EER diagram

后端 未结 3 475
逝去的感伤
逝去的感伤 2021-01-31 14:12

In MySQL Workbench\'s EER diagram, there is a checkbox to make each column in a table unique, not null, primary key etc.

However, I would like to have a UNIQUE constrain

3条回答
  •  时光取名叫无心
    2021-01-31 14:53

    In the Alter Table dialog of MySQL Workbench:

    • Go to Indexes tab.
    • Double-click on a blank row to create a new index.
    • Choose 'UNIQUE' as the index type.
    • Check the columns that you want to be unique together.

    There's some discussion as to whether this is weird, since an index is not the same as a constraint. I certainly wouldn't have thought to look there. However, apparently the `unique index' enforces uniqueness in the same way as a unique constraint, and may improve performance. For example, if I try to insert a row that would break unique together after using this method, it throws an '1062 Duplicate entry' error.

提交回复
热议问题