ALTER INDEX
Activates or deactivates an index, and rebuilds an index
DSQL, ESQL
ALTER INDEX indexname {ACTIVE | INACTIVE}
Parameter | Description |
---|---|
indexname |
Index name |
The ALTER INDEX
statement activates or deactivates an index.There is no facility on this statement for altering any attributes of the index.
INACTIVE
-
With the
INACTIVE
option, the index is switched from the active to inactive state.The effect is similar to theDROP INDEX
statement except that the index definition remains in the database.Altering a constraint index to the inactive state is not permitted.An active index can be deactivated if there are no queries prepared using that index;otherwise, an “object in use” error is returned.
Activating an inactive index is also safe.However, if there are active transactions modifying the table, the transaction containing the
ALTER INDEX
statement will fail if it has theNOWAIT
attribute.If the transaction is inWAIT
mode, it will wait for completion of concurrent transactions.On the other side of the coin, if our
ALTER INDEX
succeeds and starts to rebuild the index atCOMMIT
, other transactions modifying that table will fail or wait, according to theirWAIT
/NO WAIT
attributes.The situation is the same forCREATE INDEX
.NoteHow is it Useful?It might be useful to switch an index to the inactive state whilst inserting, updating or deleting a large batch of records in the table that owns the index.
ACTIVE
-
Rebuilds the index (even if already active), and marks it as active.
NoteHow is it Useful?Even if the index is active when
ALTER INDEX … ACTIVE
is executed, the index will be rebuilt.Rebuilding indexes can be a useful piece of housekeeping to do, occasionally, on the indexes of a large table in a database that has frequent inserts, updates or deletes but is infrequently restored.