Foreign key processing for Oracle synchronized table data

Source: Internet
Author: User

Oracle foreign key for table data synchronization method 1: When deleting data in a table with a parent-child table relationship, we all know that we need to delete the child table before deleting the data in the parent table, or cancel the foreign key and then delete it. Yesterday, we used to delete the child table first, then the parent table, and truncate to delete the child table. The following message is displayed when we delete the parent table: "Unique/foreign key reference enabled for the primary key in the table ". If it is changed to delete, the deletion is successful. The online explanation is the difference between ddl and dml. This is another difference between truncate and delete. Method 2: alter table t_user disable primary key cascade; truncate table t_user; alter table t_user enable primary key; insert into t_user ..... commit; -- query the table's primary key constraint name select * from user_constraints e where e. table_name = ''; -- enter the table name here -- Query all records that reference the primary key select B. table_name, B. column_name from user_constraints a inner join user_cons_columns B on. constraint_name = B. constraint_name where. r_constraint_name = ''; -- here Enter the constraint name of the table primary key just queried. Method 3: 1. The foreign key constraint names in the ORACLE database can be found in the user_constraints table. Constraint_type = 'R' indicates a foreign key constraint. 2. The command for enabling foreign key constraints is: alter table name enable constraint name 3. The command for disabling foreign key constraints is: alter table name disable constraint name 4. Then use SQL to find the constraint names of all foreign keys in the database: select 'alter table' | table_name | 'Enable constraint' | constraint_name | '; 'From user_constraints where constraint_type = 'R' select 'alter table' | table_name | 'Disable constraint' | constraint_name | ';' from user_constraints where constraint_type = 'R'

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.