Common Oracle Database Constraint constraints and Exception Handling

Source: Internet
Author: User

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!

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