Oracle starts and disables constraints and deletes records that violate constraints

Source: Internet
Author: User

First, disable constraints

ALTER TABLE table_name DISABLE NOVALIDATE constraint constraint_name

Second, bulk import data

Be sure to check the violation of the constraint before opening the constraint record

1. Execute the script Utlexpt1.sql from Oracle to create the exceptions table. The script is in the Oracle_home/rdbms/admin directory

Sql> @oracle_home \rdbms\admin\utlexpt1.sql

2. Execute an ALTER statement with the exception option to add a record that violates the constraint to the exceptions table to save

ALTER TABLE table_name ENABLE VALIDATE constraint constraint_name exceptions into sys.exceptions;

3. Use subqueries in the exceptions table to lock invalid rows of data

Select COLUMN1,COLUMN2,COLUMN3 from table_name where ROWID in (

Select row_id from Sys.exceptions

) for update

4, according to the query results to modify the violation of the constraint record line (can be directly updated via ROWID)

5. Re-execute the statement with ALTER OPEN constraint

ALTER TABLE table_name ENABLE VALIDATE constraint constraint_name

6, whether the state of the query constraint is enable, validate

Select constraint_name,constraint_type,status,validated from dba_constraints where owner= ' owner ' and Table_name= ' TABLE_NAME ';

Four, confirm exceptions table useless after delete or TRUNCATE TABLE

drop table sys.exceptions;

How do I restore the recyclebin in the Recycle Bin?

Sql> Flashback table Cube_scope to before drop

The table name can be the dba_recyclebin.object_name of the Recycle Bin system or it can be dba_recyclebin.original_name

But at this point, I have a backup of the DDL statement rebuilt a new table, this time again with this command to restore the obvious error, this time what to do, can only be reverted to an alias, the specific Operation command is

Sql> Flashback table Cube_scope before drop rename to Cube_scope_old

Now that you have recovered the data from the table before the deletion, you can only insert Cube_scope from the data in the Cube_scope_old

sql> INSERT INTO Cube_scope select * from Cube_scope_old t

 

Oracle starts and disables constraints and deletes records that violate constraints

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.