Learn how to work with primary indexes or partitioning for a table with or without the ALTER TABLE request, or alter the indexes using ALTER TABLE.
Redefining for a Table
- Use the ALTER TABLE MODIFY PRIMARY or PRIMARY AMP syntax to modify the primary index or primary AMP index for the table. See MODIFY PRIMARY, General Rules for the MODIFY PRIMARY Clause, and Modifying the Partitioning of a Table or Join Index.
- To change the partitioning for a table, you can specify MODIFY without specifying PRIMARY, PRIMARY AMP, or NO PRIMARY. The PRIMARY, PRIMARY AMP, or NO PRIMARY keywords are only required to modify the primary index or primary AMP index of a table.
- Create a new table with the primary index, primary AMP index, or partitioning defined properly and then use an INSERT ... SELECT to copy the data from the old table to the new table.
- Use the CREATE TABLE AS syntax to:
- Create a new table with the primary index or primary AMP index and partitioning, if required.
- Copy the rows and, if desired, the statistics from the old table into the new table.
You can use ALTER TABLE to perform the following modifications to a primary index, primary AMP index, or partitioning for a table. See General Rules for the MODIFY PRIMARY Clause, Modifying the Partitioning of a Table or Join Index, and Rules for Altering a Partitioning for a Table.
Operation | What to Specify |
---|---|
Change a NUPI to a UPI | MODIFY UNIQUE PRIMARY or PRIMARY AMP in the MODIFY PRIMARY clause. |
Change a UPI to a NUPI | MODIFY NOT UNIQUE PRIMARY or PRIMARY AMP in the MODIFY PRIMARY clause. |
Change a partitioned object to a nonpartitioned object | NOT PARTITIONED in the MODIFY PRIMARY clause. The table must be empty. |
Change a nonpartitioned object to a partitioned object | a PARTITION BY clause in the MODIFY PRIMARY clause. The table must be empty. |
Add or drop partitioning expression ranges | an ADD RANGE or DROP RANGE clause within the Primary Index Change Options clause. See Modifying Partitioning Using the ADD RANGE and DROP RANGE Options. |
Add or drop primary index or primary AMP index columns | MODIFY PRIMARY clause. The table must be empty. |
Validate partitioning by regenerating table headers and correcting any errors in row partitioning | a REVALIDATE PRIMARY INDEX clause within the REVALIDATE Options clause. See General Rules and Restrictions for the REVALIDATE Option. |
If you alter a table to have a UPI and there is already a USI defined on the same column set, the system drops the USI automatically during the ALTER TABLE operation.
A primary index cannot contain any BLOB, CLOB, ARRAY, VARRAY, Period, or Geospatial columns.
You cannot change the primary index for an error table. See Rules and Restrictions for Error Tables.
Redefining without ALTER TABLE
To redefine the primary index or partitioning for a table without using an ALTER TABLE request, see Procedure to Change Column Data Types. See one of the following methods.
First method | Second method |
---|---|
|
|
Altering Use ALTER TABLE
- Altering an empty table.
- Altering a table with a primary index or primary AMP index to have a unique or nonunique primary index.
- Altering a table to change the primary index or primary AMP index name.