Personal tools
You are here: Home DB2 How To's How to alter the data type of a column on DB2
Navigation
Log in


Forgot your password?
 
Document Actions

How to alter the data type of a column on DB2

set data type

See the example below:


Table Name:  fruit
Column name:
color


 db2 describe table fruit


Output:

Column                         Type      Type
name                           schema    name               Length   Scale Nulls
------------------------------ --------- ------------------ -------- ----- ------
COLOR                       SYSIBM    DECIMAL                  10     0 No 


Altering the data type
db2 alter table fruit alter column color set data type decimal(20)

Checking the results
db2 describe table fruit


Output:

Column                         Type      Type
name                           schema    name               Length   Scale Nulls
------------------------------ --------- ------------------ -------- ----- ------
COLOR                       SYSIBM    DECIMAL                  20     0 N


WARNING:

Don't forget to reorganize your table. The "Reorg recommended" column identifies the data type alterations that will require table reorganization before a table can again be fully accessed (SQLSTATE 57016)

db2 reorg table fruit

db2 runstats on table fruit and indexes all

If you will alter the varchar(n) column to varchar(n +x),
it is the only situation that you don't need to reorg your table.






Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls