Do you want to reduce your column length, while keeping table available in DB2 LUW?
Let me discuss a situation, you have a table in which there is a column defined as varchar(1000). This table has data too. Now due to some business requirement, you want to reduce the column length to varchar(100). You are fine with data truncation for this column, but are concerned with table availability.
In this situation, you can follow below steps,
1.Create a table with a different name(say table2), but same
structure and indexes(with different names)
2.export data like this
db2 "export to myfile.ixf of ixf messages
msgs.txt select col1,col2,,substr(varchar,1,256),..,coln from
schema.table"
3.load into new table created in step 1, like
load from myfile.ixf of ixf insert into table2
4.After successful load of all rows, rename original table to
some other name, and table2 to original table name.
The rename statements will look like,
db2 “rename table table1 to table2”
db2 “rename index index1 to index2”
And for creating staging table, we can use db2look like db2look
-d sample -e -x -t db2inst1.testvar -o tableddl.sql
With these steps original table will remain available for most
of the time.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home