Reporting Constraint Exceptions
If exceptions exist when a constraint is validated, an error is returned and the integrity constraint remains novalidated. When a statement is not successfully executed because integrity constraint exceptions exist, the statement is rolled back. If exceptions exist, you cannot validate the constraint until all exceptions to the constraint are either updated or deleted.
To determine which rows violate the integrity constraint, issue the
ALTER TABLE
statement with the EXCEPTIONS
option in the ENABLE
clause. The EXCEPTIONS
option places the rowid, table owner, table name, and constraint name of all exception rows into a specified table.
You must create an appropriate exceptions report table to accept information from the
EXCEPTIONS
option of the ENABLE
clause before enabling the constraint. You can create an exception table by executing the UTLEXCPT.SQL
script or the UTLEXPT1.SQL
script.
Both of these scripts create a table named
EXCEPTIONS
. You can create additional exceptions tables with different names by modifying and resubmitting the script.
The following statement attempts to validate the
PRIMARY KEY
of the dept
table, and if exceptions exist, information is inserted into a table namedEXCEPTIONS
:ALTER TABLE dept ENABLE PRIMARY KEY EXCEPTIONS INTO EXCEPTIONS;
If duplicate primary key values exist in the
dept
table and the name of the PRIMARY KEY
constraint on dept
is sys_c00610
, then the following query will display those exceptions:SELECT * FROM EXCEPTIONS;
Niciun comentariu:
Trimiteți un comentariu