This section describes common Oracle Database Constraint restrictions and Exception Handling. Next, let's take a look at this part.
1. Report constraints exception
If an exception exists during validation constraints, an error is returned and the integrity constraints remain unverified. If the constraint is abnormal, a statement cannot be correctly executed, and the statement is rolled back. If an exception exists, you must update or delete all exceptions of the constraints before you can verify the constraints. However, when using the alter table statement, you cannot determine which row violates the constraint. To determine which row, the alter table statement with the EXCEPTION option in the publish ENABLE clause.
The EXCEPTION option puts ROWID, OWNER, TABLE, ROWID, and CONSTRAINT in a specified TABLE. Before enabling the constraint, create a suitable EXCEPTION report table to receive the EXCEPTION option Information of the ENABLE clause. You can directly execute '? \ Rdbms \ admin \ utlexcpt. SQL 'or '? The \ rdbms \ admin \ utlexcpt1. SQL script is created. Note: The difference between the two scripts lies in the compatibility level of the database and the type of the table analyzed.
The syntax is as follows:
Alter table dept enable primary key partition tions INTO partition tions;
Or
Alter table team disable validate constraint id_num exceptions into exceptions; -- this method does not create an index.
If an exception exists, you can directly query SELECT * from exceptions. If more detailed information is required, you can associate ROWID with the ROWID of the original table, so that you can find all the information of the current row in the original table and modify it.
How to use EXCEPTIONS to solve some problems in practice:
(1) load data on existing constraint
Disable first, load the data, enable and disable tions INTO distribute tions, delete the records based on the conditions table, and then enable.
(2) create a constraint. The original data violates this constraint.
Create disable first, enable and disable tions INTO disable tions
Here is an example of creating a foreign key:
2. Common contraint operations
Define constraints:
Note: When you use a foreign key to refer to the PRIMARY or UNIQUE key, you cannot disable or delete the referenced constraint.
Enable and disable latency Verification:
Disable:
Enable non-validation:
Enable verification:
To disable/Delete the foreign key constraint:
Alter table dept disable primary key cascade;
Delete:
Some basic operations on Oracle Database Constraint constraints are introduced here. I hope this introduction will be helpful to you!