How to give a unique constraint to a combination of columns in Oracle?

霸气de小男生 提交于 2019-11-29 02:53:12
saamorim

Create a unique key on those columns

ALTER TABLE YourTable
  add CONSTRAINT YourTable_unique UNIQUE (B, C, D);

Oracle/PLSQL: Unique Constraints

First of all you should drop an existing Constraint by using below ALTER Query.

ALTER TABLE table_name
   DROP CONSTRAINT myUniqueConstraint;

Now, you can create a UNIQUE Constraint by using the keyword UNIQUE with the combination of required Columns.

For Example:

ALTER TABLE table_name
   ADD CONSTRAINT myUniqueConstraint UNIQUE(B, C, D);

Detailed explanation of UNIQUE Constraint here.

ALTER TABLE table_name DROP CONSTRAINT constraint_name;

CREATE UNIQUE INDEX constraint_name ON table_name (B,C,D)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!