Environment: Oracle 11.2.0.3 Requirements: Production of a table due to improper design, there is no primary key. Now you need to add the primary key, the amount of data is large, want to build in parallel.1. Direct ADD, hint ora-3001: not implemented function; only single-threaded primary key creation
Sql> ALTER TABLE t add constraint pk_t primary key (object_id) using index online parallel 2;alter table T add Constrai NT pk_t primary KEY (object_id) using index online parallel 2ora-03001: Features not implemented sql> ALTER TABLE t add constraint pk_t PR Imary key (object_id) using index online; Table alteredsql> ALTER TABLE t drop PRIMARY key; Table Altered
2. Consider adding a unique index in parallel before adding a primary key
Sql> Create unique index pk_t on T (object_id) Parallel 2 online;index createdsql> ALTER TABLE t add constraint pk_t Primary key (OBJECT_ID); Table alteredsql> ALTER index pk_t Noparallel;index altered
3. Compare the difference between primary key and uniqueness index
sql> desc tname Type Nullable Default Comments-------------------------------------------------- OWNER VARCHAR2 (x) y object_name VARCHAR2 (x) y Subobject_name VARCHAR2 (+) Y object_id number data_object_id number Y object_type VARCHAR2 y CREATED DATE y Last_ddl_time DATE y TIMESTAMP VARCHAR2 (x) y ST ATUs VARCHAR2 (7) Y temporary VARCHAR2 (1) y GENERATED V ARCHAR2 (1) Y secondary VARCHAR2 (1) y NAMESPACE number y Edition_name VARCHAR2 (+) Y sql> ALTER TABLE t drop PRIMARY key; Table alteredsql> desc tNaMe Type Nullable Default Comments--------------------------------------------------OWNER V ARCHAR2 (+) y object_name VARCHAR2 (x) y subobject_name VARCHAR2 (y) object_id number y data_object_id number y object_type VARCHAR2 y CREATED DATE y last _ddl_time DATE y TIMESTAMP VARCHAR2 (x) y STATUS VAR CHAR2 (7) Y temporary VARCHAR2 (1) y GENERATED VARCHAR2 (1) Y Secondary VARCHAR2 (1) y NAMESPACE number y Edition_name VARCHAR2 (Y)
Summary:For tables that already have a large amount of data that cannot be built in parallel, you can create a unique index in parallel and then add the primary key. The primary key cannot be empty, and the uniqueness index can be empty.