在多个列上创建条件唯一约束

时间:2019-06-04 20:11:21

标签: sql oracle constraints unique

我需要使用Oracle在多个列上创建条件唯一约束,但是我没有这样做。

下面是我现在所拥有的,但是它不起作用:

基本上,我的条件唯一约束需要在a = 1的条件下处理列的组合。

alter table <table_name> add constraint <constraint_name> unique (<column_1>, <column_2>, a = 1);

运行以下alter语句时出现此错误:

ORA-00907: missing right parenthesis

1 个答案:

答案 0 :(得分:1)

我相信这已经足够:

create unique index <index_name> on <table_name> (case when a = 1 then <column_1> end, 
                                                  case when a = 1 then <column_2> end); 
相关问题