Defining and altering tables with structured type columns

Creating a table with columns of structured types is for the most part no different from creating tables with only the Db2® SQL data types. For every column that is defined, a corresponding data type is assigned. For structured type columns, the structured type name is provided as the corresponding data type.

About this task

For example, the following ALTER TABLE statement adds a column of Address_t type to a Customer_List untyped table:

   ALTER TABLE Customer_List
      ADD COLUMN Address Address_t;

Now instances of Address_t or any of the subtypes of Address_t can be stored in this table.

If you are concerned with how structured types are laid out in the data record, you can use the INLINE LENGTH clause in the CREATE TYPE statement. This clause indicates the maximum size of an instance of a structured type in a column. If the size of a structured type instance is less than the defined maximum, the data is stored inline with the rest of the values in the row. If the size of the structured type exceeds the defined maximum, the structured type data is stored outside of the table (much like LOBs).

To accommodate changes you make to a structured type, you can alter the size of the affected structured type column by issuing the ALTER TABLE ALTER COLUMN SET INLINE LENGTH statement. After altering the length of a column, invoke the REORG utility.