The primary key can work with the index well

continuted:

The primary key can work with the index well even with the non unique key.

But the non unique key have to be converted to unique key index by the primary key creating command.

See following example:

SQL> create table t2 as select rownum rno from user_objects where rownum<=10;

Table created.

SQL> create index t2_idx on t2(rno);

Index created.

SQL> select * From t2;

RNO
----------
1
2
3
4
5
6
7
8
9
10

10 rows selected.

SQL> alter table t2 add constraint t2_pk primary key(rno);

Table altered.

SQL> insert into t2 values(1);
insert into t2 values(1)
*
ERROR at line 1:
ORA-00001: unique constraint (SYS.T2_PK) violated


SQL> select index_name,uniqueness from user_indexes where table_name='T2';

INDEX_NAME UNIQUENES
------------------------------ ---------
T2_IDX NONUNIQUE

你可能感兴趣的:(primary)