Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / Database concepts.pdf
Скачиваний:
29
Добавлен:
12.05.2015
Размер:
6.96 Mб
Скачать

Constraint States

Unique Constraints and Indexes

A user sees inconsistent constraints, including duplicates in unique indexes, when that user’s transaction produces these inconsistencies.

You can place deferred unique and foreign key constraints on materialized views, allowing fast and complete refresh to complete successfully.

Deferrable unique constraints always use nonunique indexes. When you remove a deferrable constraint, its index remains. This is convenient because the storage information remains available after you disable a constraint. Not-deferrable unique constraints and primary keys also use a nonunique index if the nonunique index is placed on the key columns before the constraint is enforced.

Constraint States

You can enable or disable integrity constraints at the table level using the CREATE TABLE or ALTER TABLE statement. You can also set constraints to VALIDATE or NOVALIDATE, in any combination with ENABLE or DISABLE, where:

ENABLE ensures that all incoming data conforms to the constraint

DISABLE allows incoming data, regardless of whether it conforms to the constraint

VALIDATE ensures that existing data conforms to the constraint

NOVALIDATE means that some existing data may not conform to the constraint In addition:

ENABLE VALIDATE is the same as ENABLE. The constraint is checked and is guaranteed to hold for all rows.

ENABLE NOVALIDATE means that the constraint is checked, but it does not have to be true for all rows. This allows existing rows to violate the constraint, while ensuring that all new or modified rows are valid.

In an ALTER TABLE statement, ENABLE NOVALIDATE resumes constraint checking on disabled constraints without first validating all data in the table.

DISABLE NOVALIDATE is the same as DISABLE. The constraint is not checked and is not necessarily true.

DISABLE VALIDATE disables the constraint, drops the index on the constraint, and disallows any modification of the constrained columns.

21-26 Oracle9i Database Concepts

Constraint States

For a UNIQUE constraint, the DISABLE VALIDATE state enables you to load data efficiently from a nonpartitioned table into a partitioned table using the

EXCHANGE PARTITION clause of the ALTER TABLE statement.

Transitions between these states are governed by the following rules:

ENABLE implies VALIDATE, unless NOVALIDATE is specified.

DISABLE implies NOVALIDATE, unless VALIDATE is specified.

VALIDATE and NOVALIDATE do not have any default implications for the

ENABLE and DISABLE states.

When a unique or primary key moves from the DISABLE state to the ENABLE state, if there is no existing index, a unique index is automatically created. Similarly, when a unique or primary key moves from ENABLE to DISABLE and it is enabled with a unique index, the unique index is dropped.

When any constraint is moved from the NOVALIDATE state to the VALIDATE state, all data must be checked. (This can be very slow.) However, moving from VALIDATE to NOVALIDATE simply forgets that the data was ever checked.

Moving a single constraint from the ENABLE NOVALIDATE state to the ENABLE VALIDATE state does not block reads, writes, or other DDL statements. It can be done in parallel.

See Also: Oracle9i Database Administrator’s Guide for more information about how to use the ENABLE, DISABLE, VALIDATE, and NOVALIDATE CONSTRAINT clauses.

Constraint State Modification

You can use the MODIFY CONSTRAINT clause of the ALTER TABLE statement to change the following constraint states:

DEFERRABLE or NOT DEFERRABLE

INITIALLY DEFERRED or INITIALLY IMMEDIATE

RELY or NORELY

USING INDEX ...

ENABLE or DISABLE

VALIDATE or NOVALIDATE

EXCEPTIONS INTO ...

Data Integrity 21-27

Constraint States

See Also: Oracle9i SQL Reference for information about these constraint states

21-28 Oracle9i Database Concepts

Соседние файлы в папке Oracle selected docs