How to add unique key constraint to an existing column of a table?
meda Changed status to publish 16/07/2022
Here below is a sample SQL statement to add unique key constraint to an existing column of a table:
SQL> conn mereba/mereba@to_primary Connected. --- Add unique constraint to column 'EMP_ID' of table emp_sal SQL> alter table emp_sal add constraint uk_impID UNIQUE (EMP_ID); alter table emp_sal add constraint uk_impID UNIQUE (EMP_ID) * ERROR at line 1: ORA-02261: such unique or primary key already exists in the table ---NOTE: on oracle database, primary column of a table also becomes unique column of the table by default. ----Create unique constraint on non-primary column of the table SQL> alter table emp_sal add constraint uk_jobtitle UNIQUE (jobtitle); Table altered. SQL>
meda Edited answer 20/04/2022