| Oracle8i SQL Reference Release 3 (8.1.7) Part Number A85397-01 |
|
SQL Statements:
ALTER TABLE to constraint_clause, 2 of 14
Use the ALTER TABLE statement to alter the definition of a nonpartitioned table, a partitioned table, a table partition, or a table subpartition.
The table must be in your own schema, or you must have ALTER privilege on the table, or you must have ALTER ANY TABLE system privilege. For some operations you may also need the CREATE ANY INDEX privilege.
In addition, if you are not the owner of the table, you need the DROP ANY TABLE privilege in order to use the drop_partition_clause or truncate_partition_clause.
You must also have space quota in the tablespace in which space is to be acquired in order to use the add_partition_clause, modify_partition_clause, move_partition_clause, and split_partition_clause.
To enable a UNIQUE or PRIMARY KEY constraint, you must have the privileges necessary to create an index on the table. You need these privileges because Oracle creates an index on the columns of the unique or primary key in the schema containing the table.
To enable or disable triggers, the triggers must be in your schema or you must have the ALTER ANY TRIGGER system privilege.
To use an object type in a column definition when modifying a table, either that object must belong to the same schema as the table being altered, or you must have either the EXECUTE ANY TYPE system privilege or the EXECUTE schema object privilege for the object type.
column_constraint, table_constraint, column_ref_constraint, table_ref_constraint, constraint_state: See the constraint_clause.
LOB_parameters::=
storage_clause: See storage_clause.
nested_table_storage_clause::=
object_properties::=
physical_properties::=
segment_attributes_clause::=
index_organized_table_clause::=
compression_clause::=
index_organized_overflow_clause::=
modify_collection_retrieval_clause::=
modify_storage_clauses::=
modify_LOB_storage_clause::=
modify_LOB_storage_parameters::=
modify_varray_storage_clause::=
modify_default_attributes_clause::=
partition_attributes::=
subpartition_description::=
table_partition_description::=
partition_level_subpartitioning::=
hash_partitioning_storage_clause::=
rename_partition/ subpartition_clause::=
truncate_partition_clause and truncate_subpartition_clause::=
partition_spec::=
exchange_partition_clause and exchange_subpartition_clause::=
using_index_clause::=
The clauses described below have specialized meaning in the ALTER TABLE statement. For descriptions of the remaining keywords, see CREATE TABLE.
|
Note: Operations performed by the |
schema
Specify the schema containing the table. If you omit schema, Oracle assumes the table is in your own schema.
table
Specify the name of the table to be altered.
You can modify, or drop columns from, or rename a temporary table. However, for a temporary table, you cannot:
LOB_storage_clause for an added or modified LOB column: TABLESPACE, storage_clause, LOGGING or NOLOGGING, or the LOB_index_clause.
physical_attribute_clause, nested_table_storage_clause, parallel_clause, allocate_extent_clause, deallocate_unused_clause, or any of the index_organized_table clauses
LOGGING or NOLOGGING
MOVE
Note: If you alter a table that is a master table for one or more materialized views, the materialized views are marked
INVALID. Invalid materialized views cannot be used by query rewrite and cannot be refreshed. To revalidate a materialized view, see ALTER MATERIALIZED VIEW.
add_column_options
ADD add_column_options lets you add a column or integrity constraint.
If you add a column, the initial value of each row for the new column is null unless you specify the DEFAULT clause. In this case, Oracle updates each row in the new column with the value you specify for DEFAULT. This update operation, in turn, fires any AFTER UPDATE triggers defined on the table.
You can add an overflow data segment to each partition of a partitioned index-organized table.
You can add LOB columns to nonpartitioned and partitioned tables. You can specify LOB storage at the table and at the partition or subpartition level.
If you previously created a view with a query that used the "SELECT *" syntax to select all columns from table, and you now add a column to table, Oracle does not automatically add the new column to the view. To add the new column to the view, re-create the view using the CREATE VIEW statement with the OR REPLACE clause.
Restrictions:
NOT NULL constraint if table has any rows unless you also specify the DEFAULT clause.
LOB_storage_clause
Use the LOB_storage_clause to specify the LOB storage characteristics for the newly added LOB column. You cannot use this clause to modify an existing LOB column. Instead, you must use the modify_LOB_storage_clause.
Restrictions:
LOB_parameters you can specify for a hash partition or hash subpartition is TABLESPACE.
LOB_index_clause if table is partitioned.
|
|
Specify the LOB column name or LOB object attribute for which you are explicitly defining tablespace and storage characteristics that are different from those of the table. |
|
|
|
Specify the name of the LOB data segment. You cannot use |
|
|
|
Specify whether the LOB value is to be stored in the row (inline) or outside of the row. (The LOB locator is always stored in the row regardless of where the LOB value is stored.) |
|
|
|
||
|
|
Restriction: You cannot change |
|
|
|
Specify the number of bytes to be allocated for LOB manipulation. If
You cannot change the value of |
|
|
|
||
|
|
Specify the maximum percentage of overall LOB storage space to be used for creating new versions of the LOB. The default value is 10, meaning that older versions of the LOB data are not overwritten until 10% of the overall LOB storage space is used. |
|
|
|
This clause is deprecated as of Oracle8i. Oracle generates an index for each LOB column. The LOB indexes are system named and system managed, and reside in the same tablespace as the LOB data segments. It is still possible for you to specify this clause in some cases. However, Oracle Corporation strongly recommends that you no longer do so. In any event, do not put the LOB index in a different tablespace from the LOB data.
|
|
varray_storage_clause
The varray_storage_clause lets you specify separate storage characteristics for the LOB in which a varray will be stored. In addition, if you specify this clause, Oracle will always store the varray in a LOB, even if it is small enough to be stored inline.
Restriction: You cannot specify the TABLESPACE clause of LOB_parameters as part of this clause. The LOB tablespace for a varray defaults to the containing table's tablespace.
nested_table_storage_clause
the nested_table_storage_clause lets you specify separate storage characteristics for a nested table, which in turn enables you to define the nested table as an index-organized table. You must include this clause when creating a table with columns or column attributes whose type is a nested table. (Clauses within this clause that function the same way they function for parent object tables are not repeated here.)
Restrictions:
parallel_clause.
TABLESPACE (as part of the segment_attributes_clause) for a nested table. The tablespace is always that of the parent table.
partition_storage_clause
The partition_storage_clause lets you specify a separate LOB_storage_clause or varray_storage_clause for each partition. You must specify the partitions in the order of partition position.
If you do not specify a LOB_storage_clause or varray_storage_clause for a particular partition, the storage characteristics are those specified for the LOB item at the table level. If you also did not specify any storage characteristics at the table level for the LOB item, Oracle stores the LOB data partition in the same tablespace as the table partition to which it corresponds.
Restriction: You can specify only one list of partition_storage_clauses per ALTER TABLE statement, and all LOB_storage_clauses and varray_storage_clauses must precede the list of partition_storage_clauses.
modify_column_options
Use MODIFY modify_column_options to modify the definition of an existing column. If you omit any of the optional parts of the column definition (datatype, default value, or column constraint), these parts remain unchanged.
CHAR column to VARCHAR2 (or VARCHAR) and a VARCHAR2 (or VARCHAR) to CHAR only if the column contains nulls in all rows or if you do not attempt to change the column size.
Restrictions:
|
|
Specify the name of the column to be added or modified.
The only type of integrity constraint that you can add to an existing column using the |
|
|
|
Specify a new datatype for an existing column. You can omit the datatype only if the statement also designates the column as part of the foreign key of a referential integrity constraint. Oracle automatically assigns the column the same datatype as the corresponding column of the referenced key of the referential integrity constraint. If you change the datatype of a column in a materialized view container table, the corresponding materialized view is invalidated.
|
|
|
|
Restrictions: |
|
|
|
|
|
move_table_clause
For a heap-organized table, use the segment_attributes_clause of the syntax. The move_table_clause lets you relocate data of a nonpartitioned table into a new segment, optionally in a different tablespace, and optionally modify any of its storage attributes.
You can also move any LOB data segments associated with the table using the LOB_storage_clause. (LOB items not specified in this clause are not moved.)
For an index-organized table, use the index_organized_table_clause of the syntax. The move_table_clause rebuilds the index-organized table's primary key index B*-tree. The overflow data segment is not rebuilt unless the OVERFLOW keyword is explicitly stated, with two exceptions:
PCTTHRESHOLD or the INCLUDING column as part of this ALTER TABLE statement, the overflow data segment is rebuilt.
The index and data segments of LOB columns are not rebuilt unless you specify the LOB columns explicitly as part of this ALTER TABLE statement.
Restrictions on the move_table_clause:
MOVE, it must be the first clause. For an index-organized table, the only clauses outside this clause that are allowed are the physical_attribute_clause and the parallel_clause. For heap-organized tables, you can specify those two clauses and the LOB_storage_clauses.
MOVE an entire partitioned table (either heap or index organized). You must move individual partitions or subpartitions.
physical_attributes_clause
The physical_attributes_clause lets you change the value of PCTFREE, PCTUSED, INITRANS, and MAXTRANS parameters and storage characteristics.
Restriction: You cannot specify the PCTUSED parameter for the index segment of an index-organized table.
modify_collection_retrieval_clause
Use the modify_collection_retrieval_clause to change what is returned when a collection item is retrieved from the database.
|
|
Specify the name of a column-qualified attribute whose type is nested table or varray. |
|
|
|
Specify what Oracle should return as the result of a query. |
|
modify_storage_clauses
drop_constraint_clause
The drop_constraint_clause lets you drop an integrity constraint from the database. Oracle stops enforcing the constraint and removes it from the data dictionary. You can specify only one constraint for each drop_constraint_clause, but you can specify multiple drop_constraint_clauses in one statement.
Restrictions on the drop_constraint_clause:
UNIQUE or PRIMARY KEY constraint that is part of a referential integrity constraint without also dropping the foreign key. To drop the referenced key and the foreign key together, use the CASCADE clause. If you omit CASCADE, Oracle does not drop the PRIMARY KEY or UNIQUE constraint if any foreign key references it.
CASCADE clause) on a table that uses the primary key as its object identifier (OID).
REF column, the REF column remains scoped to the referenced table.
drop_column_clause
The drop_column_clause lets you free space in the database by dropping columns you no longer need, or by marking them to be dropped at a future time when the demand on system resources is less.
BFILE column, only the locators stored in that column are removed, not the files referenced by the locators.
INCLUDING column, the column stored immediately before this column will become the new INCLUDING column.
|
|
Use |
|
|
|
You can view all tables with columns marked as unused in the data dictionary views
|
|
|
|
Unused columns are treated as if they were dropped, even though their column data remains in the table's rows. After a column has been marked as unused, you have no access to that column. A " |
|
|
|
|
|
|
|
Specify |
|
|
|
When the column data is dropped:
|
|
|
|
|
|
|
|
Specify |
|
|
|
Specify one or more columns to be set as unused or dropped. Use the |
|
|
|
Specify |
|
|
|
||
|
|
Oracle invalidates all dependent objects, such as views, triggers, and stored program units. Object invalidation is a recursive process. Therefore, all directly dependent and indirectly dependent objects are invalidated. However, only local dependencies are invalidated, because Oracle manages remote dependencies differently from local dependencies. An object invalidated by this statement is automatically revalidated when next referenced. You must then correct any errors that exist in that object before referencing it.
|
|
|
|
Specify |
|
|
|
Checkpointing cuts down the amount of undo logs accumulated during the drop column operation to avoid running out of rollback segment space. However, if this statement is interrupted after a checkpoint has been applied, the table remains in an unusable state. While the table is unusable, the only operations allowed on it are
You cannot use this clause with |
|
|
|
Specify |
|
Restrictions on the drop_column_clause:
ALTER TABLE clauses. For example, the following statements are not allowed:
ALTER TABLE t1 DROP COLUMN f1 DROP (f2);ALTER TABLE t1 DROP COLUMN f1 SET UNUSED (f2);ALTER TABLE t1 DROP (f1) ADD (f2 NUMBER);ALTER TABLE t1 SET UNUSED (f3)ADD (CONSTRAINT ck1 CHECK (f2 > 0));
CASCADE CONSTRAINTS.
allocate_extent_clause
The allocate_extent_clause lets you explicitly allocates a new extent for the table, the partition or subpartition, the overflow data segment, the LOB data segment, or the LOB index.
Restriction: You cannot allocate an extent for a range- or composite-partitioned table.
deallocate_unused_clause
Use the deallocate_unused_clause to explicitly deallocate unused space at the end of the table, partition or subpartition, overflow data segment, LOB data segment, or LOB index and makes the space available for other segments in the tablespace. You can free only unused space above the high water mark (that is, the point beyond which database blocks have not yet been formatted to receive data).
Oracle credits the amount of the released space to the user quota for the tablespace in which the deallocation occurs.
Oracle deallocates unused space from the end of the object toward the high water mark at the beginning of the object. If an extent is completely contained in the deallocation, then the whole extent is freed for reuse. If an extent is partially contained in the deallocation, then the used part up to the high water mark becomes the extent, and the remaining unused space is freed for reuse.
The exact amount of space freed depends on the values of the INITIAL, MINEXTENTS, and NEXT parameters.
CACHE | NOCACHE
MONITORING | NOMONITORING
|
|
Specify
|
|
|
|
Specify
Restriction: You cannot specify |
|
LOGGING | NOLOGGING
|
|
Specify whether subsequent Direct Loader (SQL*Loader) and direct-load INSERT operations against a nonpartitioned table, table partition, all partitions of a partitioned table, or all subpartitions of a partition will be logged (
When used with the |
|
|
|
|
|
|
|
For a table or table partition, if you omit |
|
|
|
For LOBs, if you omit
|
|
|
|
In |
|
|
|
If the database is run in |
|
|
|
The logging attribute of the base table is independent of that of its indexes. |
|
|
|
|
|
RENAME TO
|
|
Use the |
|
|
|
|
|
records_per_block_clause
The records_per_block_clause lets you specify whether Oracle restricts the number of records that can be stored in a block. This clause ensures that any bitmap indexes subsequently created on the table will be as small (compressed) as possible.
Restrictions:
MINIMIZE or NOMINIMIZE if a bitmap index has already been defined on table. You must first drop the bitmap index.
alter_overflow_clause
The alter_overflow_clause lets you change the definition of an index-organized table. Index-organized tables keep data sorted on the primary key and are therefore best suited for primary-key-based access and manipulation.
|
|
The
Restriction: You cannot specify
|
|
|
|
The For a partitioned index-organized table:
You can find the order of the partitions by querying the
If you do not specify |
|
partitioning_clauses
The following clauses apply only to partitioned tables. You cannot combine partition operations with other partition operations or with operations on the base table in one ALTER TABLE statement.
modify_default_attributes_clause
The modify_default_attributes_clause lets you specify new default values for the attributes of table. Partitions and LOB partitions you create subsequently will inherit these values unless you override them explicitly when creating the partition or LOB partition. Existing partitions and LOB partitions are not affected by this clause.
Only attributes named in the statement are affected, and the default values specified are overridden by any attributes specified at the individual partition level.
Restrictions:
PCTTHRESHOLD, COMPRESS, physical_attributes_clause, and overflow_clause are valid only for partitioned index-organized tables.
PCTUSED parameter for the index segment of an index-organized table.
COMPRESS only if compression is already specified at the table level.
The modify_partition_clause lets you change the real physical attributes of the partition table partition. Optionally modifies the storage attributes of one or more LOB items for the partition. You can specify new values for any of the following physical attributes for the partition: the logging attribute; PCTFREE, PCTUSED, INITRANS, or MAXTRANS parameter; or storage parameters.
If table is composite-partitioned:
allocate_extent_clause, Oracle will allocate an extent for each subpartition of partition.
deallocate_unused_clause, Oracle will deallocate unused storage from each subpartition of partition.
FOR PARTITION clause of the modify_default_attributes_clause.
Restriction: If table is hash partitioned, you can specify only the allocate_extent and deallocate_unused clauses. All other attributes of the partition are inherited from the table-level defaults except TABLESPACE, which stays the same as it was at create time.
modify_subpartition_clause
The modify_subpartition_clause lets you allocate or deallocate storage for an individual subpartition of table.
Restriction: The only modify_LOB_storage_parameters you can specify for subpartition are the allocate_extent_clause and deallocate_unused_clause.
UNUSABLE LOCAL INDEXES marks UNUSABLE all the local index subpartitions associated with subpartition.
REBUILD UNUSABLE LOCAL INDEXES rebuilds the unusable local index subpartitions associated with subpartition.
rename_partition/ subpartition_clause
Use the rename_partition_clause or rename_subpartition_clause to rename a table partition or subpartition current_name to new_name. For both partitions and subpartitions, new_name must be different from all existing partitions and subpartitions of the same table.
move_partition_clause
Use the move_partition_clause to move table partition partition to another segment. You can move partition data to another tablespace, recluster data to reduce fragmentation, or change create-time physical attributes.
If the table contains LOB columns, you can use the LOB_storage_clause to move the LOB data and LOB index segments associated with this partition. Only the LOBs named are affected. If you do not specify the LOB_storage_clause for a particular LOB column, its LOB data and LOB index segments are not moved.
If partition is not empty, MOVE PARTITION marks UNUSABLE all corresponding local index partitions and all global nonpartitioned indexes, and all the partitions of global partitioned indexes.
When you move a LOB data segment, Oracle drops the old data segment and corresponding index segment and creates new segments even if you do not specify a new tablespace.
The move operation obtains its parallel attribute from the parallel_clause, if specified. If not specified, the default parallel attributes of the table, if any, are used. If neither is specified, Oracle performs the move without using parallelism.
The parallel_clause on MOVE PARTITION does not change the default parallel attributes of table.
Restrictions:
partition is a hash partition, the only attribute you can specify in this clause is TABLESPACE.
move_subpartition_clause.
move_subpartition_clause.
move_subpartition_clause
Use the move_subpartition_clause to move the table subpartition subpartition to another segment. If you do not specify TABLESPACE, the subpartition will remain in the same tablespace.
Unless the subpartition is empty, Oracle marks UNUSABLE all local index subpartitions corresponding to the subpartition being moved, as well as global nonpartitioned indexes and partitions of global indexes.
If the table contains LOB columns, you can use the LOB_storage_clause to move the LOB data and LOB index segments associated with this subpartition. Only the LOBs named are affected. If you do not specify the LOB_storage_clause for a particular LOB column, its LOB data and LOB index segments are not moved.
When you move a LOB data segment, Oracle drops the old data segment and corresponding index segment and creates new segments even if you do not specify a new tablespace.
add_range_partition_clause
The add_range_partition_clause lets you add a new range partition partition to the "high" end of a partitioned table (after the last existing partition). You can specify any create-time physical attributes for the new partition. If the table contains LOB columns, you can also specify partition-level attributes for one or more LOB items.
You can specify up to 64K-1 partitions.
|
See Also: Oracle8i Administrator's Guide for a discussion of factors that might impose practical limits less than this number |
Restrictions:
MAXVALUE, you cannot add a partition to the table. Instead, use the split_partition_clause to add a partition at the beginning or the middle of the table.
compression_clause, physical_attributes_clause, and OVERFLOW are valid only for a partitioned index-organized table.
PCTUSED parameter for the index segment of an index-organized table.
OVERFLOW only if the partitioned table already has an overflow segment.
|
|
Specify the upper bound for the new partition. The |
|
|
|
The |
|
|
|
|
|
|
|
The subpartitions inherit all their attributes from any attributes specified for |
|
|
|
This clause overrides any subpartitioning specified at the table level.
If you do not specify this clause but you specified default subpartitioning at the table level,
|
|
add_hash_partition_clause
The add_hash_partition_clause lets you add a new hash partition to the "high" end of a partitioned table. Oracle will populate the new partition with rows rehashed from other partitions of table as determined by the hash function.
You can specify a name for the partition, and optionally a tablespace where it should be stored. If you do not specify new_partition_name, Oracle assigns a partition name of the form SYS_Pnnn. If you do not specify TABLESPACE, the new partition is stored in the table's default tablespace. Other attributes are always inherited from table-level defaults.
|
|
lets you specify whether to parallelize the creation of the new partition. |
|
coalesce_partition_clause
COALESCE applies only to hash-partitioned tables. This clause specifies that Oracle should select a hash partition, distribute its contents into one or more remaining partitions (determined by the hash function), and then drop the selected partition. Local index partitions corresponding to the selected partition are also dropped. Oracle marks UNUSABLE, and you must rebuild, the local index partitions corresponding to one or more absorbing partitions.
drop_partition_clause
The drop_partition_clause applies only to tables partitioned using the range or composite method. This clause removes partition partition, and the data in that partition, from a partitioned table. If you want to drop a partition but keep its data in the table, you must merge the partition into one of the adjacent partitions.
If the table has LOB columns, the LOB data and LOB index partitions (and their subpartitions, if any) corresponding to partition are also dropped.
partition, even if they are marked UNUSABLE.
UNUSABLE all global nonpartitioned indexes defined on the table and all partitions of global partitioned indexes, unless the partition being dropped or all of its subpartitions are empty.
Restriction: If table contains only one partition, you cannot drop the partition. You must drop the table.
truncate_partition_clause and truncate_subpartition_clause
TRUNCATE PARTITION removes all rows from partition or, if the table is composite-partitioned, all rows from partition's subpartitions. TRUNCATE SUBPARTITION removes all rows from subpartition.
If the table contains any LOB columns, the LOB data and LOB index segments for this partition are also truncated. If the table is composite-partitioned, the LOB data and LOB index segments for this partition's subpartitions are truncated.
If the partition or subpartition to be truncated contains data, you must first disable any referential integrity constraints on the table. Alternatively, you can delete the rows and then truncate the partition.
For each partition or subpartition truncated, Oracle also truncates corresponding local index partitions and subpartitions. If those index partitions or subpartitions are marked UNUSABLE, Oracle truncates them and resets the UNUSABLE marker to VALID. In addition, if the truncated partition or subpartition, or any of the subpartitions of the truncated partition are not empty, Oracle marks as UNUSABLE all global nonpartitioned indexes and partitions of global indexes defined on the table.
split_partition_clause
The split_partition_clause lets you create, from an original partition partition_name_old, two new partitions, each with a new segment and new physical attributes, and new initial extents. The segment associated with partition_name_old is discarded.
Restriction: You cannot specify this clause for a hash-partitioned table.
If you specify subpartitioning for the new partitions, you can specify only TABLESPACE for the subpartitions. All other attributes will be inherited from the containing new partition.
If partition_name_old is subpartitioned, and you do not specify any subpartitioning for the new partitions, the new partitions will inherit the number and tablespaces of the subpartitions in partition_name_old.
Oracle also splits corresponding local index partitions, even if they are marked UNUSABLE. The resulting local index partitions inherit all their partition-level default attributes from the local index partition being split.
If partition_name_old was not empty, Oracle marks UNUSABLE all global nonpartitioned indexes and all partitions of global indexes on the table. (This action on global indexes does not apply to index-organized tables.) In addition, if any partitions or subpartitions resulting from the split are not empty, Oracle marks as UNUSABLE all corresponding local index partitions and subpartitions.
If table contains LOB columns, you can use the LOB_storage_clause to specify separate LOB storage attributes for the LOB data segments resulting from the split. Oracle drops the LOB data and LOB index segments of partition_name_old and creates new segments for each LOB column, for each partition, even if you do not specify a new tablespace.
merge_partitions_clause
The merge_partitions_clause lets you merge the contents of two adjacent partitions of table into one new partition, and then drops the original two partitions.
The new partition inherits the partition-bound of the higher of the two original partitions.
Any attributes not specified in the segment_attributes_clause are inherited from table-level defaults.
If you do not specify a new partition_name, Oracle assigns a name of the form SYS_Pnnn. If the new partition has subpartitions, Oracle assigns subpartition names of the form SYS_SUBPnnn.
If either or both of the original partitions was not empty, Oracle marks UNUSABLE all global nonpartitioned global indexes and all partitions of global indexes on the table. In addition, if the partition or any of its subpartitions resulting from the merge is not empty, Oracle marks UNUSABLE all corresponding local index partitions and subpartitions.
Restriction: You cannot specify this clause for an index-organized table or for a table partitioned using the hash method.
exchange_partition_clause and exchange_subpartition_clause
Use the EXCHANGE PARTITION or EXCHANGE SUBPARTITION clause to exchange the data and index segments of
All of the segment attributes of the two objects (including tablespace) are also exchanged.
The default behavior is EXCLUDING INDEXES WITH VALIDATION. You must have ALTER TABLE privileges on both tables to perform this operation.
This clause facilitates high-speed data loading when used with transportable tablespaces.
If table contains LOB columns, for each LOB column Oracle exchanges LOB data and LOB index partition or subpartition segments with corresponding LOB data and LOB index segments of table.
All statistics of the table and partition are exchanged, including table, column, index statistics, and histograms. The aggregate statistics of the table receiving the new partition are recalculated.
The logging attribute of the table and partition is also exchanged.
Restriction: Both tables involved in the exchange must have the same primary key, and no validated foreign keys can be referencing either of the tables unless the referenced table is empty.
|
|
Specify the table with which the partition will be exchanged. |
|
|
|
Specify |
|
|
|
Specify |
|
|
|
Specify |
|
|
|
Specify |
|
|
|
Specify a table into which Oracle should place the rowids of all rows violating the constraint. If you omit |
|
|
|
You can create the |
|
|
|
If you create your own exceptions table, it must follow the format prescribed by one of these two scripts. |
|
|
|
|
|
|
|
Restrictions on |
|
|
|
If these conditions are not true, Oracle ignores this clause. |
|
Restrictions on exchanging partitions:
When exchanging between a hash-partitioned table and the range partition of a composite-partitioned table, the following restrictions apply:
UNUSABLE all global indexes on both tables.
For partitioned index-organized tables, the following additional restrictions apply:
row_movement_clause
The row_movement_clause determines whether a row can be moved to a different partition or subpartition because of a change to one or more of its key values.
Restriction: You can specify this clause only for partitioned tables.
parallel_clause
The parallel_clause lets you change the default degree of parallelism for queries and DML on the table.
Restrictions:
table contains any columns of LOB or user-defined object type, subsequent INSERT, UPDATE, and DELETE operations on table are executed serially without notification. Subsequent queries, however, will be executed in parallel.
parallel_clause in conjunction with the move_table_clause, the parallelism applies only to the move, not to subsequent DML and query operations on the table.
enable_disable_clause
The enable_disable_clause lets you specify whether Oracle should apply an integrity constraint.
TABLE LOCK
Oracle permits DDL operations on a table only if the table can be locked during the operation. Such table locks are not required during DML operations.
ALL TRIGGERS
|
|
Specify
To enable a single trigger, use the
|
|
|
|
Specify |
|
The following statement modifies the storage characteristics of a nested table column projects in table emp so that when queried it returns actual values instead of locators:
ALTER TABLE emp MODIFY NESTED TABLE projects RETURN AS VALUE;
PARALLEL Example
The following statement specifies parallel processing for queries to the emp table:
ALTER TABLE emp PARALLEL;
ENABLE VALIDATE Example
The following statement places in ENABLE VALIDATE state an integrity constraint named fk_deptno in the emp table:
ALTER TABLE emp ENABLE VALIDATE CONSTRAINT fk_deptno EXCEPTIONS INTO except_table;
Each row of the emp table must satisfy the constraint for Oracle to enable the constraint. If any row violates the constraint, the constraint remains disabled. Oracle lists any exceptions in the table except_table. You can also identify the exceptions in the EMP table with the following statement:
SELECT emp.* FROM emp e, except_table ex WHERE e.row_id = ex.row_id AND ex.table_name = 'EMP' AND ex.constraint = 'FK_DEPTNO';
ENABLE NOVALIDATE Example
The following statement tries to place in ENABLE NOVALIDATE state two constraints on the emp table:
ALTER TABLE emp ENABLE NOVALIDATE UNIQUE (ename) ENABLE NOVALIDATE CONSTRAINT nn_ename;
This statement has two ENABLE clauses:
ename column in ENABLE NOVALIDATE state.
nn_ename in ENABLE NOVALIDATE state.
In this case, Oracle enables the constraints only if both are satisfied by each row in the table. If any row violates either constraint, Oracle returns an error and both constraints remain disabled.
Consider a referential integrity constraint involving a foreign key on the combination of the areaco and phoneno columns of the phone_calls table. The foreign key references a unique key on the combination of the areaco and phoneno columns of the customers table. The following statement disables the unique key on the combination of the areaco and phoneno columns of the customers table:
ALTER TABLE customers DISABLE UNIQUE (areaco, phoneno) CASCADE;
The unique key in the customers table is referenced by the foreign key in the phone_calls table, so you must use the CASCADE clause to disable the unique key. This clause disables the foreign key as well.
CHECK Constraint Example
The following statement defines and disables a CHECK constraint on the emp table:
ALTER TABLE emp ADD (CONSTRAINT check_comp CHECK (sal + comm <= 5000) ) DISABLE CONSTRAINT check_comp;
The constraint check_comp ensures that no employee's total compensation exceeds $5000. The constraint is disabled, so you can increase an employee's compensation above this limit.
The following statement enables all triggers associated with the emp table:
ALTER TABLE emp ENABLE ALL TRIGGERS;
DEALLOCATE UNUSED Example
The following statement frees all unused space for reuse in table emp, where the high water mark is above MINEXTENTS:
ALTER TABLE emp DEALLOCATE UNUSED;
DROP COLUMN Example
This statement illustrates the drop_column_clause with CASCADE CONSTRAINTS. Assume table t1 is created as follows:
CREATE TABLE t1 ( pk NUMBER PRIMARY KEY, fk NUMBER, c1 NUMBER, c2 NUMBER, CONSTRAINT ri FOREIGN KEY (fk) REFERENCES t1, CONSTRAINT ck1 CHECK (pk > 0 and c1 > 0), CONSTRAINT ck2 CHECK (c2 > 0) );
An error will be returned for the following statements:
ALTER TABLE t1 DROP (pk); -- pk is a parent key ALTER TABLE t1 DROP (c1); -- c1 is referenced by multicolumn constraint ck1
Submitting the following statement drops column pk, the primary key constraint, the foreign key constraint, ri, and the check constraint, ck1:
ALTER TABLE t1 DROP (pk) CASCADE CONSTRAINTS;
If all columns referenced by the constraints defined on the dropped columns are also dropped, then CASCADE CONSTRAINTS is not required. For example, assuming that no other referential constraints from other tables refer to column pk, then it is valid to submit the following statement without the CASCADE CONSTRAINTS clause:
ALTER TABLE t1 DROP (pk, fk, c1);
This statement modifies the INITRANS parameter for the index segment of index-organized table docindex:
ALTER TABLE docindex INITRANS 4;
The following statement adds an overflow data segment to index-organized table docindex:
ALTER TABLE docindex ADD OVERFLOW;
This statement modifies the INITRANS parameter for the overflow data segment of index-organized table docindex:
ALTER TABLE docindex OVERFLOW INITRANS 4;
ADD PARTITION Example
The following statement adds a partition p3 and specifies storage characteristics for three of the table's LOB columns (b, c, and d):
ALTER TABLE pt ADD PARTITION p3 VALUES LESS THAN (30) LOB (b, d) STORE AS (TABLESPACE tsz) LOB (c) STORE AS mylobseg;
The LOB data and LOB index segments for columns b and d in partition p3 will reside in tablespace tsz. The remaining attributes for these LOB columns will be inherited first from the table-level defaults, and then from the tablespace defaults.
The LOB data segments for column c will reside in the mylobseg segment, and will inherit all other attributes from the table-level defaults and then from the tablespace defaults.
SPLIT PARTITION Example
The following statement splits partition p3 into partitions p3_1 andp3_2:
ALTER TABLE pt SPLIT PARTITION p3 AT (25) INTO (PARTITION p3_1 TABLESPACE ts4 LOB (b,d) STORE AS (TABLESPACE tsz), PARTITION p3_2 (TABLESPACE ts5) LOB (c) STORE AS (TABLESPACE ts5);
In partition p3_1, Oracle creates the LOB segments for columns b and d in tablespace tsz. In partition p3_2, Oracle creates the LOB segments for column c in tablespace ts5. The LOB segments for columns b and d in partition p3_2 and those for column c in partition p3_1 remain in original tablespace for the original partition p3. However, Oracle creates new segments for all the LOB data and LOB index segments, even though they are not moved to a new tablespace.
The following statements create an object type, a corresponding object table with a primary-key-based object identifier, and a table having a user-defined REF column:
CREATE TYPE emp_t AS OBJECT (empno NUMBER, address CHAR(30)); CREATE TABLE emp OF emp_t ( empno PRIMARY KEY) OBJECT IDENTIFIER IS PRIMARY KEY; CREATE TABLE dept (dno NUMBER, mgr_ref REF emp_t SCOPE is emp);
The next statements add a constraint and a user-defined REF column, both of which reference table emp:
ALTER TABLE dept ADD CONSTRAINT mgr_cons FOREIGN KEY (mgr_ref) REFERENCES emp; ALTER TABLE dept ADD sr_mgr REF emp_t REFERENCES emp;
The following statement adds a column named thriftplan of datatype NUMBER with a maximum of seven digits and two decimal places and a column named loancode of datatype CHAR with a size of one and a NOT NULL integrity constraint:
ALTER TABLE emp ADD (thriftplan NUMBER(7,2), loancode CHAR(1) NOT NULL);
The following statement increases the size of the thriftplan column to nine digits:
ALTER TABLE emp MODIFY (thriftplan NUMBER(9,2));
Because the MODIFY clause contains only one column definition, the parentheses around the definition are optional.
The following statement changes the values of the PCTFREE and PCTUSED parameters for the emp table to 30 and 60, respectively:
ALTER TABLE emp PCTFREE 30 PCTUSED 60;
ALLOCATE EXTENT Example
The following statement allocates an extent of 5 kilobytes for the emp table and makes it available to instance 4:
ALTER TABLE emp ALLOCATE EXTENT (SIZE 5K INSTANCE 4);
Because this statement omits the DATAFILE parameter, Oracle allocates the extent in one of the datafiles belonging to the tablespace containing the table.
This statement modifies the bal column of the accounts table so that it has a default value of 0:
ALTER TABLE accounts MODIFY (bal DEFAULT 0);
If you subsequently add a new row to the accounts table and do not specify a value for the bal column, the value of the bal column is automatically 0:
INSERT INTO accounts(accno, accname) VALUES (accseq.nextval, 'LEWIS'); SELECT * FROM accounts WHERE accname = 'LEWIS'; ACCNO ACCNAME BAL ------ ------- --- 815234 LEWIS 0
To discontinue previously specified default values, so that they are no longer automatically inserted into newly added rows, replace the values with nulls, as shown in this statement:
ALTER TABLE accounts MODIFY (bal DEFAULT NULL);
The MODIFY clause need only specify the column name and the modified part of the definition, rather than the entire column definition. This statement has no effect on any existing values in existing rows.
The following statement drops the primary key of the dept table:
ALTER TABLE dept DROP PRIMARY KEY CASCADE;
If you know that the name of the PRIMARY KEY constraint is pk_dept, you could also drop it with the following statement:
ALTER TABLE dept DROP CONSTRAINT pk_dept CASCADE;
The CASCADE clause drops any foreign keys that reference the primary key.
The following statement drops the unique key on the dname column of the dept table:
ALTER TABLE dept DROP UNIQUE (dname);
The DROP clause in this statement omits the CASCADE clause. Because of this omission, Oracle does not drop the unique key if any foreign key references it.
The following statement adds CLOB column resume to the employee table and specifies LOB storage characteristics for the new column:
ALTER TABLE employee ADD (resume CLOB) LOB (resume) STORE AS resume_seg (TABLESPACE resume_ts);
To modify the LOB column resume to use caching, enter the following statement:
ALTER TABLE employee MODIFY LOB (resume) (CACHE);
The following statement adds the nested table column skills to the employee table:
ALTER TABLE employee ADD (skills skill_table_type) NESTED TABLE skills STORE AS nested_skill_table;
You can also modify a nested table's storage characteristics. Use the name of the storage table specified in the nested_table_storage_clause to make the modification. You cannot query or perform DML statements on the storage table. Use the storage table only to modify the nested table column storage characteristics.
The following statement creates table vetservice with nested table column client and storage table client_tab. Nested table vetservice is modified to specify constraints:
CREATE TYPE pet_table AS OBJECT (pet_name VARCHAR2(10), pet_dob DATE); CREATE TABLE vetservice (vet_name VARCHAR2(30), client pet_table) NESTED TABLE client STORE AS client_tab; ALTER TABLE client_tab ADD UNIQUE (ssn);
The following statement adds a UNIQUE constraint to nested table nested_skill_table:
ALTER TABLE nested_skill_table ADD UNIQUE (a);
The following statement alters the storage table for a nested table of REF values to specify that the REF is scoped:
CREATE TYPE emp_t AS OBJECT (eno number, ename char(31)); CREATE TYPE emps_t AS TABLE OF REF emp_t; CREATE TABLE emptab OF emp_t; CREATE TABLE dept (dno NUMBER, employees emps_t) NESTED TABLE employees STORE AS deptemps; ALTER TABLE deptemps ADD (SCOPE FOR (column_value) IS emptab);
Similarly, to specify storing the REF with rowid:
ALTER TABLE deptemps ADD (REF(column_value) WITH ROWID);
In order to execute these ALTER TABLE statements successfully, the storage table deptemps must be empty. Also, because the nested table is defined as a table of scalars (REFs), Oracle implicitly provides the column name COLUMN_VALUE for the storage table.
|
See Also:
|
In the following statement an object type dept_t has been previously defined. Now, create table emp as follows:
CREATE TABLE emp (name VARCHAR(100), salary NUMBER, dept REF dept_t);
An object table DEPARTMENTS is created as:
CREATE TABLE departments OF dept_t;
The dept column can store references to objects of dept_t stored in any table. If you would like to restrict the references to point only to objects stored in the departments table, you could do so by adding a scope constraint on the dept column as follows:
ALTER TABLE emp ADD (SCOPE FOR (dept) IS departments);
The above ALTER TABLE statement will succeed only if the emp table is empty.
If you want the REF values in the dept column of emp to also store the rowids, issue the following statement:
ALTER TABLE emp ADD (REF(dept) WITH ROWID);
The following statement adds partition jan99 to tablespace tsx:
ALTER TABLE sales ADD PARTITION jan99 VALUES LESS THAN( '970201' ) TABLESPACE tsx;
The following statement drops partition dec98:
ALTER TABLE sales DROP PARTITION dec98;
The following statement converts partition feb97 to table sales_feb97 without exchanging local index partitions with corresponding indexes on sales_feb97 and without verifying that data in sales_feb97 falls within the bounds of partition feb97:
ALTER TABLE sales EXCHANGE PARTITION feb97 WITH TABLE sales_feb97 WITHOUT VALIDATION;
The following statement marks all the local index partitions corresponding to the nov96 partition of the sales table UNUSABLE:
ALTER TABLE sales MODIFY PARTITION nov96 UNUSABLE LOCAL INDEXES;
The following statement rebuilds all the local index partitions that were marked UNUSABLE:
ALTER TABLE sales MODIFY PARTITION jan97 REBUILD UNUSABLE LOCAL INDEXES;
The following statement changes MAXEXTENTS and logging attribute for partition branch_ny:
ALTER TABLE branch MODIFY PARTITION branch_ny STORAGE (MAXEXTENTS 75) LOGGING;
The following statement moves partition depot2 to tablespace ts094:
ALTER TABLE parts MOVE PARTITION depot2 TABLESPACE ts094 NOLOGGING;
The following statement renames a table:
ALTER TABLE emp RENAME TO employee;
In the following statement, partition emp3 is renamed:
ALTER TABLE employee RENAME PARTITION emp3 TO employee3;
The following statement splits the old partition depot4, creating two new partitions, naming one depot9 and reusing the name of the old partition for the other:
ALTER TABLE parts SPLIT PARTITION depot4 AT ( '40-001' ) INTO ( PARTITION depot4 TABLESPACE ts009 STORAGE (MINEXTENTS 2), PARTITION depot9 TABLESPACE ts010 ) PARALLEL (10);
The following statement deletes all the data in the sys_p017 partition and deallocates the freed space:
ALTER TABLE deliveries TRUNCATE PARTITION sys_p017 DROP STORAGE;
For examples of defining integrity constraints with the ALTER TABLE statement, see the constraint_clause.
For examples of changing the value of a table's storage parameters, see the .
|
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|