Search code examples
sqloracle11guniquealter

Oracle 11g - add new column and set as unique


I am facing a problem on how to set a new column to unique using Oracle 11g.

I try to use this code but it getting error:

ALTER TABLE QAS_ASSIGNED_STATE ADD UNIQUE (cuid);

Solution

  • You should define column's type. Like this:

    alter table
        QAS_ASSIGNED_STATE 
     add
        cuid number NULL;
    

    and then add constraint:

    ALTER TABLE QAS_ASSIGNED_STATE ADD CONSTRAINT constraint_cuid  UNIQUE (cuid );