ALTER TABLE Statement
With the ALTER TABLE statement, you can make the following column changes:
For instructions on using the ALTER TABLE statement, see the SQL Reference Guide.
Considerations
The definition of the table is updated to include the new column definition, and the new column becomes the last column in the table. Table rows are not updated as part of the ALTER TABLE processing; instead, the column is added to an existing row only when that row is next updated.
When adding a column, if the table is not empty, you much supply a default value for the added column. You do this in one of the following ways:
Note: For more information about choosing a value, see the SQL Reference Guide.
If a new column in a compressed table will be used as an index key or as a referencing column, consider placing the column near the front of the table. Otherwise, the compression potential of the table will be greatly reduced.
To do this, the table must be dropped and re-added with a new column order. When you put the rows back into the table, make sure the data is in the new column order.
Adding a column to a table does not impact existing programs or view definitions except under the following circumstances:
Allowing a column to have a default value affects only the table’s definition; existing table rows are not affected.
If the table is populated and the column does not allow null values, every existing row must contain a value in the changed column. To ensure this, each row is accessed and updated if it does not contain a value for the column.
A column that is named in a check constraint or a view cannot be renamed.
The definition of all referential constraints, sort keys, CALC keys and indexes in which the column participates are updated to show the new column name.
Every row in the table is updated to remove the column value.
If a column is named in a check constraint or is part of the CALC key of a populated table, you cannot drop the column.
If you do not specify CASCADE, the column must not be one of the following types of columns:
If you specify CASCADE, how the column is used determines what other items are dropped:
The following situations apply when you change a column's null attribute:
The following situations apply when you change a column's data type:
Adding a column to a table or changing a column's attributes might increase the length of the table row beyond the maximum allowed.
For compressed tables, the maximum is 32760. If the new column would cause this to be exceeded, the column cannot be added to the table; instead, consider creating a second table to hold the additional information.
For uncompressed tables, the maximum depends on the page size of the area in which the table resides. If the new column would cause the length of the row to be greater than (page size - 40), then do one of the following:
Note: For more information about EXPAND PAGE, see the Utilities Guide.
Note: The maximum length of an uncompressed row can be as much as (page size - 40); however, it is recommended that row lengths be no more than 30% of the size of the page.
If an area is becoming full, consider expanding its space before increasing the length of table rows. The chapter “Modifying Physical Database Definitions” describes methods you can use to expand an area.
|
Copyright © 2014 CA.
All rights reserved.
|
|