Oracle changes the primary-foreign key relationship type and does not destroy the original data

Source: Internet
Author: User

You need to delete the foreign key and primary key first, and store data by creating temporary fields (to reserve the customer's original data ), finally, re-establish the primary key and foreign key 1. Delete the relationship between the primary key and foreign key "the column type is not compatible with the referenced column type" alter table Name drop constraint relationship name; 2. Run the following statement to report "to modify the data type, the column to be changed must be blank"
Alter table name modify (target field varchar2 (100 ));


Step 1: Add a temporary field to the table
Alter table name add temporary field Original Type of target field;

Step 2: pay the value of the target field to the temporary field and leave the target field empty.
Update table name set temporary field = target field, target field = null;

Step 3: Modify the target type
Alter table name modify target field varchar2 (100 );

Step 4: pay the value of the temporary field to the target field and leave the temporary field empty.
Update table name set target field = temporary field, temporary field = null;

The last step is to delete temporary fields.
Alter table Name drop column temporary field;

3. Create a primary key-foreign key relationship

Alter table primary key table add constraint PK_CC_NAME primary key (field name)
Using index
Tablespace *** pctfree 10
Initrans 2
Maxtrans 255
Initial 64 K
Minextents 1
Maxextents unlimited

Alter table foreign key table add constraint FK_CC_NAME foreign key (field name)
References primary key table (field name );

Related Article

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: 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.