且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在MySQL Workbench EER图中的多列上创建UNIQUE约束

更新时间:2023-01-31 08:12:20

在MySQL Workbench的Alter Table对话框中:

In the Alter Table dialog of MySQL Workbench:

  • 转到索引"标签.
  • 双击空白行以创建新索引.
  • 选择"UNIQUE"作为索引类型.
  • 检查您想一起唯一的列.

对于这是否很奇怪,有一些讨论,因为索引是与约束不同.我当然不会想去那里看.但是,显然,唯一索引"以与唯一约束相同的方式强制执行唯一性,并且可以提高性能.例如,如果我尝试插入使用此方法后将打破唯一性的行,则会引发"1062 Duplicate entry"错误.

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.