Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Shanmukha.

Asked: February 07, 2026 - 6:49 am UTC

Last updated: February 19, 2026 - 2:45 pm UTC

Version: 19c

You Asked

creating unique key and primary key on same column is possible? already unique key and not null constrains there on same column but still i want to create primary key without dropping unique key.

and Connor said...

That depends ... If you currently have a unique INDEX then you can add a primary key and it will automatically use that index

SQL> create table t ( x int );

Table created.

SQL> insert into t values (1);

1 row created.

SQL> commit;

Commit complete.

SQL>
SQL> create unique index ix on t ( x );

Index created.

SQL>
SQL> alter table t add constraint pk primary key ( x );

Table altered.

SQL>
SQL> select count(*) from user_indexes where table_name = 'T';

  COUNT(*)
----------
         1


However if you already have a unique CONSTRAINT then you cannot add a primary key on the same column

SQL> create table t ( x int );

Table created.

SQL> insert into t values (1);

1 row created.

SQL> commit;

Commit complete.

SQL>
SQL> alter table t add constraint ix unique ( x );

Table altered.

SQL>
SQL> alter table t add constraint pk primary key ( x );
alter table t add constraint pk primary key ( x )
                                *
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table


In that instance, making the column non nullable will be equivalent to a primary key