DB2 V8 FP2 on AIX 5.1
over 2 million row table
We need to alter a table for one field from CHAR 4 to CHAR 10 but the problem is this field is referenced in many other tables with constraints, indexes etc etc.
What I would like to know what is the best way to update the table(s) where this fiels is referenced.
We have come up with a strategy but are worried about the transaction log filling up (this has bitten us in the past) and if this is the best way to go about doing it as well?
Any feedback would be appreciated.
Mark
Here is the way we were thinking about doing and it and some more background information:
DB2 Change for CUSTOMER_ID – Change from CHAR(4) to CHAR(10)
Scope:
CUSTOMER_ID appears in the following tables:
AVC_TRANSACTION
BUSINESS_USER
CLIENT_CUSTOMER_LINE_OF_SERVICE
CUSTOMER
SUB_CUSTOMER
WEB_EXTRACT_RULES
WEB_VOLUME
It appears in the following key table/constraints
BUSINESS_USER
constraint P_IDENTIFIER_1 primary key (USER_ID, CUSTOMER_ID)
CLIENT_CUSTOMER_LINE_OF_SERVICE
constraint P_IDENTIFIER_1 primary key (CLIENT_ID, CUSTOMER_ID, LINE_OF_SERVICE_ID)
CUSTOMER
constraint P_IDENTIFIER_1 primary key (CUSTOMER_ID)
WEB_EXTRACT_RULES
constraint P_KEY_1 primary key (RULE_ID, EXTRACT_ENABLED_DATE, LINE_OF_SERVICE_ID,
USER_ID, CLIENT_ID, CUSTOMER_ID, FOLDER_NAME_ORDER)
WEB_VOLUME
constraint P_KEY_1 primary key (ARCHIVE_SITE_ID, VOLUME_DATE, CLIENT_ID, LINE_OF_SERVICE_ID,
ADJUSTMENT_FLAG, USER_ID, CUSTOMER_ID, WEB_TYPE, FOLDER_NAME)
It appears in the following foreign key table/constraints
AVC_TRANSACTION
constraint F_REFERENCE_15 foreign key (CUSTOMER_ID)
references CUSTOMER (CUSTOMER_ID)
constraint F_REFERENCE_21 foreign key (USER_ID, CUSTOMER_ID)
references BUSINESS_USER (USER_ID, CUSTOMER_ID)
BUSINESS_USER
constraint F_REFERENCE_16 foreign key (CUSTOMER_ID)
references CUSTOMER (CUSTOMER_ID)
CLIENT_CUSTOMER_LINE_OF_SERVICE
constraint F_REFERENCE_17 foreign key (CUSTOMER_ID)
references CUSTOMER (CUSTOMER_ID)
WEB_EXTRACT_RULES
constraint F_WEBEXTR_CUSTOMER foreign key (CUSTOMER_ID)
references CUSTOMER (CUSTOMER_ID)
It appears in the following indexes
WEBEXTR_CUSTOMER_F
REFERENCE_15_FK on AVC_TRANSACTION (CUSTOMER_ID ASC)
REFERENCE_21_FK on AVC_TRANSACTION (USER_ID ASC, CUSTOMER_ID ASC)
REFERENCE_16_FK on BUSINESS_USER (CUSTOMER_ID ASC)
REFERENCE_17_FK on CLIENT_CUSTOMER_LINE_OF_SERVICE (CUSTOMER_ID ASC)
WEBEXTR_CUSTOMER_F on WEB_EXTRACT_RULES (CUSTOMER_ID ASC)
Implementation Approach
1. Disable bb monitoring. (no bogus email alerts)
2. Stop shredders. (XML)
3. backup database.
4. define copy tables
(AVC_TRANSACTION2,BUSINESS_USER2, CLIENT_CUSTOMER_LINE_OF_SERVICE2, CUSTOMER2,
SUB_CUSTOMER2, WEB_EXTRACT_RULES2, WEB_VOLUME2).
5. copy 7 tables to new tables just defined.
6. drop restrict on drop to 7 tables
7. drop all indexes, constraints on 7 original tables.
AVC_TRANSACTION,BUSINESS_USER, CLIENT_CUSTOMER_LINE_OF_SERVICE, CUSTOMER,
SUB_CUSTOMER, WEB_EXTRACT_RULES, WEB_VOLUME.
8. drop original 7 tables.
9. recreate original 7 tables with expanded column definition.
10. copy the 7 copy tables back to the 7 original tables.
11. add constraints, indexes back in to the original 7 tables.
12. add restrict on drop to 7 tables.
13. drop 7 copy tables.
14. backup database.
15. start shredders.
16. re-enable bb monitoring.