Writing applications that enable users to create and modify tables
You can write a Db2 application that enables users to create new tables, add columns to them, increase the length of columns, rearrange the columns, and drop columns.
Procedure
To create new tables:
- Use the CREATE TABLE statement.
To add columns or increase the length of columns:
- Use the ALTER TABLE statement with the ADD COLUMN clause
or the ALTER COLUMN clause. Added columns initially contain either the null value or a default value. Both CREATE TABLE and ALTER TABLE, like any data definition statement, are relatively expensive to execute. Also consider the effects of locks.
To drop columns:
- Use the ALTER TABLE statement
with the DROP COLUMN clause. Dropping a column from a table is a pending-definition change unless the table space is defined with the DEFINE NO option. The column is not removed from the table until the REORG utility is run on the table space. If you are planning on dropping a column from a table in addition to making other changes to the table, make all changes that take effect immediately, prior to issuing the ALTER TABLE statement with the DROP COLUMN clause.
To rearrange columns:
- Drop the table and create the table again, with the columns
you want, in the order you want. Consider creating a view on the table, which includes only the columns that you want, in the order that you want, as an alternative to redefining the table.