Enterprise Edition Home |
Express Edition Home |
Previous Page | Next Page SQL Statements > CREATE INDEX >
You
must observe the following rules when you specify modes for unique indexes
in CREATE INDEX statements:
- You can set the mode of a unique index to enabled, disabled, or filtering.
- If you do not specify a mode, then by default the index is enabled.
- For an index set to filtering mode, if you do not specify an error option,
the default is WITHOUT ERROR.
- When you add a new unique index to an existing base table and specify
the disabled mode for the index, your CREATE INDEX statement succeeds even
if duplicate values in the indexed column would cause a unique-index violation.
- When you add a new unique index to an existing base table and specify
the enabled or filtering mode for the index, your CREATE INDEX statement succeeds
provided that no duplicate values exist in the indexed column that would cause
a unique-index violation. However, if any duplicate values exist in the indexed
column, your CREATE INDEX statement fails and returns an error.
- When you add a new unique index to an existing base table in the enabled
or filtering mode, and duplicate values exist in the indexed column, erroneous
rows in the base table are not filtered to the violations table. Thus, you
cannot use a violations table to detect the erroneous rows in the base table.
Adding a Unique Index When Duplicate Values Exist in the Column
If you attempt to add a unique index in the enabled mode but receive an
error message because duplicate values are in the indexed column, take the
following steps to add the index successfully:
- Add the index in the disabled mode. Issue the CREATE INDEX statement again,
but this time specify the DISABLED keyword.
- Start a violations and diagnostics table for the target table with the
START VIOLATIONS TABLE statement.
- Issue a SET Database Object Mode statement to change the mode of the index
to enabled. When you issue this statement, existing rows in the target table
that violate the unique-index requirement are duplicated in the violations
table. You receive an integrity-violation error message, however, and the
index remains disabled.
- Issue a SELECT statement on the violations table to retrieve the nonconforming
rows that are duplicated from the target table. You might need to join the
violations and diagnostics tables to get all the necessary information.
- Take corrective action on the rows in the target table that violate the
unique-index requirement.
- After you fix all the nonconforming rows in the target table, issue the
SET Database Object Mode statement again to switch the disabled index to the
enabled mode. This time the index is enabled, and no integrity violation error
message is returned because all rows in the target table now satisfy the new
unique-index requirement.
Enterprise Edition Home |
Express Edition Home |
[ Top of Page | Previous Page | Next Page | Contents |
Index ]