多个列上的DB2唯一约束 [英] DB2 Unique Constraint over multiple Columns

查看:1492
本文介绍了多个列上的DB2唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 独特的键`uniqueKey`(` Field1`,'Field2`),

我发现唯一的一个是直接在



提前感谢

解决方案

你应该能够添加唯一的约束:

  alter table t add constraint unq_field1_field2 unique(field1,field2)

与其他数据库一样,这几乎完全相当于创建索引。不同的是约束被命名 - 这可以方便跟踪约束和理解错误消息。


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.

Thanks in advance!

解决方案

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.

这篇关于多个列上的DB2唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆