Entering content frame

MODIFY definition 

You can modify data types and properties of table columns by specifying a MODIFY definition in the ALTER TABLE statement.

Syntax

<modify_definition> ::= MODIFY (<column_name> [<data_type>] [<column_attributes>]...)

column_name, data_type, column_attributes

The parentheses are not necessary if the MODIFY definition only contains one column name.

Explanation

Each column name must be a column of the base table specified in the ALTER TABLE statement.

Column Attributes (column_attributes)

Only the following column attributes are allowed:

·        NULL
NULL value

·        NOT NULL
If NOT NULL is specified, the table must not have any rows that contain a NULL value in the corresponding column. A NULL value can no longer be inserted into the column after being modified.

·        DEFAULT specification
The DEFAULT specification DEFAULT SERIAL is not permitted.
If a DEFAULT specification is specified, it replaces an existing DEFAULT specification in the corresponding column. The new DEFAULT specification only affects subsequent INSERT statements and not affect rows that already exist in the table.

Data types

If a DEFAULT specification is not specified and if a DEFAULT specification is defined for the corresponding column, it must be compatible with the data type.

·        Code attribute ASCII: the corresponding column must have the data type DATE, TIME, or TIMESTAMP or the code attribute ASCII or UNICODE before it is modified.

·        Code attribute UNICODE: A transformation from UNICODE to ASCII must be possible for the relevant column.

·        Code attribute BYTE: the corresponding column must have the data type DATE, TIME, or TIMESTAMP or the code attribute ASCII or BYTE before it is modified.

Data type CHAR(n), VARCHAR(n): the corresponding column must have the data type CHAR (n), VARCHAR (n), DATE, TIME, or TIMESTAMP. In this case, the table must not contain a row in which the column has a value with a length greater than n.
If a column had the code attribute UNICODE before the ALTER TABLE statement was executed, and the new code attribute is not UNICODE, transformation to the new code attribute must be possible.

Data type DATE: the corresponding column must have the data type CHAR(n), VARCHAR(n), or DATE . This column must contain a date value in any of the date formats supported by the database system in all rows of the table.

Data type FIXED(n,m): the corresponding column must have the data type FIXED (n,m), FLOAT, INT, or SMALLINT. In this case, the table must not contain a row in which the column has a value with more than (n - m) integral or m fractional digits.

Data type FLOAT(n): the corresponding column must have the data type FIXED(n,m), FLOAT(n), INT, or SMALLINT.

Data type INT: the corresponding column must have the data type FIXED(n,m), FLOAT(n), INT, or SMALLINT. In this case, the table must only contain rows in which this column has integral values in the range between -2147483648 and 2147483647.

Data type SMALLINT: the corresponding column must have the data type FIXED(n,m), FLOAT(n), INT, or SMALLINT. In this case, the table must only contain rows in which this column has integral values in the range between -32768 and 32767.

Data type TIME: the corresponding column must have the data type CHAR(n), VARCHAR(n), or TIME . This column must contain a time value in any of the time formats supported by the database system in all rows of the table.

Data type TIMESTAMP: the corresponding column must have the data type CHAR(n), VARCHAR(n), or TIMESTAMP . This column must contain a timestamp value in any of the timestamp formats supported by the database system in all rows of the table.

Column attribute NULL: a NULL value can be entered in the corresponding column with a subsequent INSERT or UPDATE statement.

If one of the columns identified by column name is contained in a search condition for the table, this column must also define a legal search condition after the data type has been modified.

Others

Depending on the type of modification, the MODIFY definition may result in the table having to be recopied and/or indexes rebuilt. If this happens, the runtime will be correspondingly long.

If a table is recopied and the table contains columns marked as deleted, then these columns are removed from the database catalog and from the table rows, thus reducing the space requirements of the table.

 

Leaving content frame