DB2 对多列的唯一约束 [英] DB2 Unique Constraint over multiple Columns
本文介绍了DB2 对多列的唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法像在 Mysql 中一样在多个列上创建唯一约束?
Is there a way to create a unique constraint over multiple columns like in Mysql?
UNIQUE KEY `uniqueKey` (`Field1`,`Field2`),
我唯一找到的是字段后面的唯一关键字.
The only thing i have found is the unique keyword directly after the field.
提前致谢!
推荐答案
你应该能够添加一个唯一的约束为:
You should be able to add a unique constraint as:
ALTER TABLE t ADD CONSTRAINT unq_field1_field2 UNIQUE(field1, field2)
与其他数据库一样,这几乎完全等同于创建索引.不同的是,给约束命名——这样可以方便跟踪约束和理解错误信息.
As with other databases, this is almost exactly equivalent to creating an index. The difference is that the constraint is named -- which can be convenient for tracking constraints and understanding error messages.
注意,如果匹配索引不存在,那么唯一索引是 自动创建.
Notice, that if the matching index does not exist, then a unique index is automatically created.
这篇关于DB2 对多列的唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文