The ALTER TYPE statement is used to add or drop attributes of a user-defined structured type.
Invocation
This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared. However, if the bind option DYNAMICRULES BIND applies, the statement cannot be dynamically prepared (SQLSTATE 42509).
Authorization
The privileges held by the authorization ID of the statement must include as least one of the following:
Syntax
>>-ALTER TYPE--type-name----------------------------------------> .-,-----------------------------------------------. V | >---------+-ADD ATTRIBUTE--| attribute-definition |--+--+------>< '-DROP ATTRIBUTE--attribute-name-----------'
Description
Notes
Examples
Example 1: The ALTER TYPE statement can be used to permit a cycle of mutually referencing types and tables. Consider mutually referencing tables named EMPLOYEE and DEPARTMENT.
The following sequence would allow the types and tables to be created.
CREATE TYPE DEPT ... CREATE TYPE EMP ... (including attribute named DEPTREF of type REF(DEPT)) ALTER TYPE DEPT ADD ATTRIBUTE MANAGER REF(EMP) CREATE TABLE DEPARTMENT OF DEPT ... CREATE TABLE EMPLOYEE OF EMP (DEPTREF WITH OPTIONS SCOPE DEPARTMENT) ALTER TABLE DEPARTMENT ALTER COLUMN MANAGER ADD SCOPE EMPLOYEE
The following sequence would allow these tables and types to be dropped.
DROP TABLE EMPLOYEE (the MANAGER column in DEPARTMENT becomes unscoped) DROP TABLE DEPARTMENT ALTER TYPE DEPT DROP ATTRIBUTE MANAGER DROP TYPE EMP DROP TYPE DEPT
Example 2: The ALTER TYPE statement can be used to create a type with an attribute that references a subtype.
CREATE TYPE EMP ... CREATE TYPE MGR UNDER EMP ... ALTER TYPE EMP ADD ATTRIBUTE MANAGER REF(MGR)