How Oracle adds primary keys in parallel

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.