You can modify an existing table to take advantage of the storage-saving benefits of compression using the ALTER TABLE command.
You must decide whether you want to use row compression only, value compression only, or both types of compression. Row compression will almost always yield benefits in terms of storage savings, as it attempts to replace data patterns that span multiple columns within a row with shorter symbol strings. Value compression can offer savings when you have a many rows with columns that contain the same value, or when you have columns that contain the default value for the data type of the column. When value compression is enabled, you can also specify that columns that assume the system default value for their data types can be further compressed with the COMPRESS SYSTEM DEFAULT option.
Restrictions
If you attempt to apply compression to columns that contain system default values using the COMPRESS SYSTEM DEFAULT clause, you must also specify VALUE COMPRESSION. Otherwise, a warning is returned, and system default values are not stored using minimal space.
If you are planning to enable value compression, be aware that the row size can, in some cases, grow as result of the overhead imposed by the database manager in dealing with certain data types. You can determine the impact that value compression has on row size using the information provided about this option in the documentation for the CREATE TABLE statement.
This task assumes that you have a table that currently does not employ row or value compression, and that you want to activate one or both of these storage-saving features.
If you altered the table, but did not perform a REORG, the format of the existing rows or columns of the table are not modified in any way, although any subsequent rows appended, updated, inserted or loaded will take advantage of whatever compression you have enabled. If you did perform a REORG, then whatever type of compression you enabled with the ALTER TABLE statement will apply to all rows of the table.
Example 1: Applying row compression to an existing table CUSTOMER.
ALTER TABLE CUSTOMER COMPRESS YES
Example 2: Applying row, value and system default compression to the SALARY column of an existing table EMPLOYEE_SALARY.
ALTER TABLE EMPLOYEE_SALARY
ALTER SALARY COMPRESS SYSTEM DEFAULT
COMPRESS YES ACTIVATE VALUE COMPRESSION;
REORG TABLE EMPLOYEE_SALARY