Search code examples
sqldb2db2-luw

DB2: How to add new column between existing columns?


I have an existing DB2 database and a table named employee with columns id,e_name,e_mobile_no,e_dob,e_address.

How can I add a new column e_father_name before e_mobile_no?


Solution

  • I always do the following --

    • Take a backup/dump of table data and db2look (If you dump to a CSV file as I do I suggest dumping in the new format so for example put null for the new column in the right place.

    • Drop table and indexes

    • Create table with the new colunn

    • Load data with old values

    • Recreate all indexes and runstats.

    Once you have done it a few times it becomes old hat.