问题描述
在MySQL Workbench的EER图中,有一个复选框使表中的每一列都是唯一的,而不是null,主键等.
In MySQL Workbench's EER diagram, there is a checkbox to make each column in a table unique, not null, primary key etc.
但是,我想对多列使用UNIQUE约束.是否可以在MySQL Workbench的EER图中添加它?
However, I would like to have a UNIQUE constraint on multiple columns. Is it possible to add it in in MySQL Workbench's EER diagram?
好的,我意识到了唯一的复选框,创建了唯一索引,而不是唯一约束
Ok, I realised the unique checkbox, creates a UNIQUE INDEX, and not a UNIQUE CONSTRAINT
推荐答案
在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.
这篇关于在MySQL Workbench EER图中的多列上创建UNIQUE约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!