Examples of redefining a table by using the ALT line command

You can use the ALT line command to make changes to your tables. With ALT, you can make both changes that are done by ALTER TABLE statements and changes that cannot be done by ALTER TABLE statements. Because ALT supports more than just ALTER statement changes, the ALT process is referred to as redefining a table.

Identity columns: If you are redefining a table that contains an identity column and the table is dropped and re-created, the column definition becomes GENERATED BY DEFAULT to preserve current data values. The first value that is generated for the identity column (specified in the START WITH clause) is also changed. The new START WITH value, which is the value that is to assigned next to the identity column, is the last unassigned value (MAXASSIGNEDVAL in SYSIBM.SYSSEQUENCES) plus the increment value (INCREMENT in SYSIBM.SYSSEQUENCES). If values were cached, any existing unassigned values in the cache that have not been used are lost. Loss of unassigned cached values causes a gap between the last assigned value of the identity column and the new starting value.

Inserting a column

Procedure

To insert a column:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the table to be changed.
  4. On the ALTER Table (ADB27C) panel, issue the I line command against the column after which you want to insert a new column:
    Figure 1. ALTER Table (ADB27C) panel- Inserting a column
    Start of change
     ADB27C in ------------------- DD1A ALTER Table ------------------ Row 1 from 5 
     Command ===>                                                  Scroll ===> PAGE 
                                                                                     
     New schema . . DSN8D10   >                    Old schema: DSN8D10              
     New name . . . DEPT                >          Old name  : DEPT                 
     New owner  . . DSN8D10   > Type:   (U/R)      Old owner : DSN8D10  
     Partitions ==> 1         Action    : NONE     New DB    : DSN8D81A              
     Rows/Page    : 48.188                         New TS    : DSN8S81D              
     Commands :  NEXT CONSTRAINTS TBLOPTS  LONGNAMES            HASH               
     Line commands :                                                                 
      I - Insert  U - Update  D - Delete  R - Repeat   LAB - Label  COM - Comment    
      M - Move    A - After   B - Before  X - Index    RES - Reset update            
      ? - Show all line commands                                                     
                                                                       Old Operation 
     Select Column Name        Col No Col Type Length  Scale Null D Col No Type      
            *                       * *             *      * *    *      * *         
     ------ ------------------ ------ -------- ------ ------ ---- - ------ --------- 
                                                                                     
            DEPTNO                  1 CHAR          3      0 N    N      1           
     I      DEPTNAME                2 VARCHAR      36      0 N    N      2           
            MGRNO                   3 CHAR          6      0 Y    Y      3           
            ADMRDEPT                4 CHAR          3      0 N    N      4           
            LOCATION                5 CHAR         16      0 Y    Y      5           
     ******************************* END OF DB2 DATA *******************************
     
    End of change
  5. For the line that contains INSERT in the Operation Type column, complete the fields that contain ? as shown to define the new column, and press Enter:
    Figure 2. ALTER Table (ADB27C) panel - Specifying attributes for the inserted column
    Start of change
    ADB27C in ------------------- DD1A ALTER Table --------------- Row 1 to 6 of 6 
    Command ===>                                                  Scroll ===> PAGE 
                                                                                   
    New schema . . DSN8A10   >                    Old schema: DSN8A10              
    New name . . . DEPT                >          Old name  : DEPT                 
    Partitions . : 0                              New DB  . . DSN8DA1A             
    Rows per page: 53                             New TS  . . DSN8SA1D             
                                                                                   
    Commands:  CONTINUE  CONSTRAINTS TBLOPTS  LONGNAMES            HASH                           
    Line commands:                                                                 
     I - Insert  U - Update  D - Delete  R - Repeat  LAB - Label  COM - Comment    
     M - Move    A - After   B - Before  X - Index   RES - Reset update            
     ? - Show all line commands                                                     
                                                                     Old Operation 
    Sel Column Name        Col No Col Type      Length  Scale N D Col No Type      
        *                       * *                  *      * * *      * *         
    --- -----------------> ------ -------- ----------- ------ - - ------ --------- 
                                                                                   
        DEPTNO                  1 CHAR               3      0 N N      1           
    *   DEPTNAME                2 VARCHAR           36      0 N N      2           
        BUILDING                3 CHAR               0      0 ? ?      0 INSERT    
        MGRNO                   4 CHAR               6      0 Y Y      3           
        ADMRDEPT                5 CHAR               3      0 N N      4           
        LOCATION                6 CHAR              16      0 Y Y      5           
    ******************************* END OF DB2 DATA *******************************
    End of change
  6. If you want to specify additional attributes for the new column, use the U line command, and on the ALTER Table (ADB26CTU) panel, specify the updated values, and press Enter:
    Figure 3. ALTER Table (ADB26CTU) panel
    Start of change
     ADB26CTU  ----------------------- DD1A ALTER Table ---------------------- 10:08
     Command ===>                                                                   
                                                                                    
                                                                         
      DB2 Admin ALTER (column number 2)      Schema . : DSN81010           >                  
                                             Name . . : DEPT               >
      Commands:  NEXTCOL  
    
      Press ENTER to continue, END to cancel, or NEXTCOL to move to the next column.      
      
      Column name  . . NEWCOL             
      Column type  . . CHAR               (CHAR,DECIMAL,INTEGER,SMALLINT,etc.)      
      Data length  . . 1                                                            
      Inline length  .                    (0-32680 BLOB or CLOB, 0-16340 DBCLOB)    
      Precision  . . .                    (FLOAT and DECIMAL only)                  
      Scale  . . . . .                    (DECIMAL and TIMESTAMP only)              
      Type schema  . .                    (User-defined type schema)                
      Type name  . . .                    (User-defined type name) 
      CCSID  . . . . . 1208               (1208 VARCHAR, 1200 VARGRAPHIC)                
      WITH TIME ZONE .                    (Yes/No - for TIMESTAMP only)             
                                                                                    
      Allow Nulls  . . NO   (Yes-Nullable, No-NOT NULL)                             
      FOR ? DATA . . .      (B - Bit, S - SBCS, M - Mixed, or blank)                
      WITH DEFAULT . . NO   (Yes, No, L (SECLABEL) or enter value below)            
      Default value  .                                                              
      HIDDEN . . . . . NO   (Yes/No)                                                
                                                                                   
      GENERATED  . . . CP (A-ALWAYS,                  D-DEFAULT,                    
                           I-ALWAYS AS IDENTITY,      J-DEFAULT AS IDENTITY         
                           E-ALWAYS AS UPD TIMESTAMP, F-DEFAULT AS UPD TIMESTAMP,   
                           Q-ALWAYS AS ROW BEGIN,     R-ALWAYS AS ROW END,          
                           O-ALWAYS AS DATA CHANGE OPERATION,                       
                           X-ALWAYS AS TRANSACTION START ID,                        
                           CA,CP,CT,CI,CW,CV,CS,CU - Special registers,             
                           SN,SS,SV - Session variables)
      FIELDPROC                                                                     
      Program name . .                                                              
      Program parm . .                                                     >        
    End of change
  7. On the ALTER Table (ADB27C) panel, issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  8. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.

Updating a column

Procedure

To update a column:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the table to be changed.
  4. On the ALTER Table (ADB27C) panel, type over the fields for any column that you want to update.
  5. If you want to update column attributes that are not displayed on the ALTER Table (ADB27C) panel, issue the U line command against the column:
    Figure 4. ALTER Table (ADB27C) panel - Updating a column
    Start of change
    ADB27C in ------------------- DD1A ALTER Table --------------- Row 1 to 5 of 5 
    Command ===>                                        Scroll ===> CSR  
                                                                                   
    New schema . . DSN8D10   >                    Old schema: DSN8D10              
    New name . . . DEPT                >          Old name  : DEPT                 
    New owner  . . DSN8D10   > Type:   (U/R)      Old owner : DSN8D10                  
    Partitions . : 1                              New DB  . . DSN8D10A             
    Rows per page: 47                             New TS  . . DSN8S10D             
                                                                                   
    Commands :  NEXT CONSTRAINTS TBLOPTS  LONGNAMES            HASH                       
    Line commands :                                                                
      I - Insert  U - Update  D - Delete  R - Repeat   LAB - Label  COM - Comment  
      M - Move    A - After   B - Before  X - Index    RES - Reset update          
      ? - Show all line commands                                                    
                                                                     Old Operation 
    Sel Column Name        Col No Col Type      Length  Scale N D Col No Type      
        *                       * *                  *      * * *      * *         
    --- -----------------> ------ -------- ----------- ------ - - ------ --------- 
                                                                                   
        DEPTNO                  1 CHAR               3      0 N N      1           
        DEPTNAME                2 VARCHAR           36      0 N N      2           
        MGRNO                   3 CHAR              16      0 Y Y      3           
        ADMRDEPT                4 CHAR               3      0 N N      4           
    U   LOCATION                5 CHAR              16      0 Y Y      5           
    ******************************* END OF DB2 DATA *******************************
    End of change
  6. On the ALTER Table (ADB26CTU) panel, specify updated values for any attributes, and press Enter:
    Figure 5. ALTER Table (ADB26CTU) panel
    Start of change
     ADB26CTU  ----------------------- DD1A ALTER Table ---------------------- 10:27
     Command ===>                                                                   
                                                                                    
                                                                        
       DB2 Admin ALTER (column number 6)     Schema . : DSN81010           >                  
                                             Name . . : DEPT               > 
      Commands:  NEXTCOL       
    
      Press ENTER to continue, END to cancel, or NEXTCOL to move to the next column
    
      Column name  . . LOCATION                                 
      Column type  . . CHAR               (CHAR,DECIMAL,INTEGER,SMALLINT,etc.)      
      Data length  . . 16                                                           
      Inline length  .                    (0-32680 BLOB or CLOB, 0-16340 DBCLOB)    
      Precision  . . .                    (FLOAT and DECIMAL only)                  
      Scale  . . . . .                    (DECIMAL and TIMESTAMP only)              
      Type schema  . .                    (User-defined type schema)                
      Type name  . . .                    (User-defined type name)                  
      WITH TIME ZONE .                    (Yes/No - for TIMESTAMP only)             
                                                                                    
      Allow Nulls  . . YES  (Yes-Nullable, No-NOT NULL)                             
      FOR ? DATA . . .      (B - Bit, S - SBCS, M - Mixed, or blank)                
      WITH DEFAULT . . YES  (Yes, No, L (SECLABEL) or enter value below)            
      Default value  . NULL                                                         
      HIDDEN . . . . . NO   (Yes/No)                                                
                                                                                   
      GENERATED  . . . CP (A-ALWAYS,                  D-DEFAULT,                    
                           I-ALWAYS AS IDENTITY,      J-DEFAULT AS IDENTITY         
                           E-ALWAYS AS UPD TIMESTAMP, F-DEFAULT AS UPD TIMESTAMP,   
                           Q-ALWAYS AS ROW BEGIN,     R-ALWAYS AS ROW END,          
                           O-ALWAYS AS DATA CHANGE OPERATION,                       
                           X-ALWAYS AS TRANSACTION START ID,                        
                           CA,CP,CT,CI,CW,CV,CS,CU - Special registers,             
                           SN,SS,SV - Session variables)      
      FIELDPROC   
      Program name . .                                                              
      Program parm . .                                                     >                                                                   
    End of change

    If you altered a primary key column of a table, an additional primary command, ADDFK, is displayed on the ALTER Table (ADB27C) panel. ADDFK propagates the primary key column updates for the target table to all tables that are affected by the update. If you specify ADDFK, all affected tables are displayed on the Alter Objects (ADB27CA) panel and included in the subsequently generated JCL for the ALTER. Submit that JCL and skip the remaining steps.

  7. On the ALTER Table (ADB27C) panel, issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  8. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.

Adding a unique key to a table

Procedure

To add a unique key to a table:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the table to which you want to add a unique key.
  4. On the ALTER Table (ADB27C) panel, issue the CONSTRAINTS primary command.

    If any constraints exist on the table, the Alter - Unique Constraints (ADBP7CN) panel lists the primary key and unique key constraints.

  5. If the Alter - Unique Constraints (ADBP7CN) panel is displayed, issue the ADD primary command.
  6. On the Create Primary or Unique Key (ADBP7CTP) panel, specify the following options for the unique key, and issue the NEXT command:
    • In the Constraint name field, type a name for the constraint.
    • In the Type field, specify whether the key is a primary or a unique key.
    • For the columns in the table, use the nn line command to specify the relative position of the column in the key.
  7. If the ALTER Table (ADB27C) panel is not displayed, press PF3 until that panel is displayed.
  8. On the ALTER Table (ADB27C) panel, issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  9. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.

Changing a unique key

Procedure

To change a unique key:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the table for which you want to alter a unique key.
  4. On the ALTER Table (ADB27C) panel, issue the CONSTRAINTS primary command.

    The Alter - Unique Constraints (ADBP7CN) panel lists the primary key and unique key constraints for the table. If this panel is not displayed, no constraints exist on the table.

  5. Issue the A line command against the constraint that you want to alter.
  6. On the resulting panel, either the Alter Primary Key (ADBP7CTP) panel or Alter Unique Key (ADBP7CTP) panel, specify the options that you want to change, and issue the NEXT command:
    • If you are changing a primary key, in the Constraint name field, type a new name.
    • Use the nn line command to change the relative position of the column in the key.
  7. Press PF3 to return to the ALTER Table (ADB27C) panel.
  8. On the ALTER Table (ADB27C) panel, issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  9. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.
Start of change

Adding a column to a primary key

About this task

When you add a column to a primary key, the underlying index that enforces that constraint needs to be changed at the same time. (This index is called the primary index.) The complete change can be made using a single ALT command.

Procedure

To add a column to a primary key:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the table whose primary key you want to alter, and press Enter.
  4. On the ALTER Table (ADB27C) panel, issue the CONSTRAINTS primary command, and press Enter.
  5. On the Alter - Unique Constraints (ADBP7CN) panel, issue the A line command against the primary key that you want to alter, and press Enter.
    The Alter Primary Key (ADBP7CTP) panel displays the current primary key.

    In the following example, the key includes columns INT1 and INT2, in that order:

     ADBP7CTP  --------------- DD1A Alter Primary Key ------------- Row 1 to 5 of 5 
                                                                                    
     Table schema  . . . : TS6462                                                   
     Table name  . . . . : PKTAB                                                    
     Constraint name . . : INT1                > Type . . : PRIMARY                 
                                                                                    
     BUSINESS_TIME WITHOUT OVERLAPS . . . NO   (Yes/No)                             
                                                                                    
     Commands: NEXT                                                                 
     Line commands:  nn - Sequence  R - Remove column sequence                      
                                                                                    
     Select Column Name        Col Seq Col Type      Length  Scale Nulls Period     
            *                        * *                  *      * *     *          
     ------ ------------------ ------- -------- ----------- ------ ----- ------     
            NAME                     0 CHAR              24      0 N                
            INT1                     1 INTEGER            4      0 N                
            INT2                     2 INTEGER            4      0 N                
            INT3                     0 INTEGER            4      0 N                
            INT4                     0 INTEGER            4      0 Y                
     ******************************* END OF DB2 DATA *******************************
  6. To add a column to the primary key, specify a sequence number in the Select column, and press Enter.

    For example, to add the INT3 column to the primary key, specify 3 next to INT3:

     ADBP7CTP  --------------- DD1A Alter Primary Key ------------- Row 1 to 5 of 5 
                                                                                    
     Table schema  . . . : TS6462                                                   
     Table name  . . . . : PKTAB                                                    
     Constraint name . . : INT1                > Type . . : PRIMARY                 
                                                                                    
     BUSINESS_TIME WITHOUT OVERLAPS . . . NO   (Yes/No)                             
                                                                                    
     Commands: NEXT                                                                 
     Line commands:  nn - Sequence  R - Remove column sequence                      
                                                                                    
     Select Column Name        Col Seq Col Type      Length  Scale Nulls Period     
            *                        * *                  *      * *     *          
     ------ ------------------ ------- -------- ----------- ------ ----- ------     
            NAME                     0 CHAR              24      0 N                
            INT1                     1 INTEGER            4      0 N                
            INT2                     2 INTEGER            4      0 N                
     3      INT3                     0 INTEGER            4      0 N                
            INT4                     0 INTEGER            4      0 Y                
     ******************************* END OF DB2 DATA *******************************
                                                                                    
                                                                                    
    After you press Enter, the Seq column is updated:
     ADBP7CTP  --------------- DD1A Alter Primary Key ------------- Row 1 to 5 of 5 
                                                                                    
     Table schema  . . . : TS6462                                                   
     Table name  . . . . : PKTAB                                                    
     Constraint name . . : INT1                > Type . . : PRIMARY                 
                                                                                    
     BUSINESS_TIME WITHOUT OVERLAPS . . . NO   (Yes/No)                             
                                                                                    
     Commands: NEXT                                                                 
     Line commands:  nn - Sequence  R - Remove column sequence                      
                                                                                    
     Select Column Name        Col Seq Col Type      Length  Scale Nulls Period     
            *                        * *                  *      * *     *          
     ------ ------------------ ------- -------- ----------- ------ ----- ------     
            NAME                     0 CHAR              24      0 N                
            INT1                     1 INTEGER            4      0 N                
            INT2                     2 INTEGER            4      0 N                
     *      INT3                     3 INTEGER            4      0 N                
            INT4                     0 INTEGER            4      0 Y                
     ******************************* END OF DB2 DATA *******************************
                                                                                    
                                                                                    

    You can also make other changes on this panel, such as changing the name of the constraint or removing columns from the sequence. You can make multiple changes to the table during this ALT session.

  7. Issue the NEXT command, and press Enter.
  8. On the Alter - Unique Constraints (ADBP7CN) panel, press PF3 to exit the panel.
  9. On the ALTER Table (ADB27C) panel, issue the NEXT command and press Enter.
    The following warning message is displayed:
    Primary index required.

    This warning is a reminder that you must also alter the primary index to include the added column.

  10. On the ALT - Related Objects (ADBP7REL) panel, specify the A line command next to the index to add it to the list of altered objects, and press Enter.
  11. Press PF3 to exit the panel.
  12. On the Alter Objects (ADB27CA) panel, specify the A line command next to the index, and press Enter.
  13. On the Redefine Index (ADB21XAR) panel, specify a sequence number next to the column that you just added to the primary key, and press Enter.

    For example, specify 3 next to INT3:

    ADB21XAR  --------------- DD1A Redefine Index ---------------- Row 1 to 3 of 5 
                                                                                   
    Commands: NEXT   ORIGINAL                                                      
    Line commands: nnn A|D - Sequence & order  R - Remove the column  I - Include  
     A - Ascending  D - Descending  RA - Random   U - Update expression/XML pattern
     ? - Show all line commands                                                    
                                                                                   
    CREATE INDEX TS6462     . PIDX                >                                
              ON TS6462.PKTAB                                                      
    Owner  . . . . . .           > Owner type . . . . .   (U/R)                    
                                                                                   
    Unique . . . . . . YES         Where Not Null . . .      Cluster . . . . . NO  
    Buffer Pool  . . . BP0         Close Rule . . . . . YES  Copy Allowed  . . NO  
    Piece Size . . . . 4194304     Define . . . . . . . YES  Defer . . . . . .     
    Partitioned  . . .             Padded . . . . . . .      Compress  . . . . NO  
    Exclude Null Keys  NO                                                          
                                                                                   
    Select Column Name        Col Type      Length  Scale N ColSeq Ord OldSeq Ord  
           *                  *                  *      * *      * *        * *    
    ------ ------------------ -------- ----------- ------ - ------ --- ------ ---  
           INT1               INTEGER            4      0 N      1 A        1 A    
           INT2               INTEGER            4      0 N      2 A        2 A    
           NAME               CHAR              24      0 N                       
    3      INT3               INTEGER            4      0 N                        
           INT4               INTEGER            4      0 Y                         
    After you press Enter, the ColSeq column is updated.
  14. Issue NEXT until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed:
  15. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.
End of change

Renaming a table

Procedure

To rename a table:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the REN line command against the table that you want to rename.
  4. On the Rename Table (ADB21TR) panel, in the New name field, specify the new name, and press Enter.
  5. If the Statement Execution Prompt (ADB2PSTM) panel is displayed, enter the appropriate action to execute the RENAME statement.

Adding a partition to a table

Procedure

To add a partition to a table:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the partitioned table to which you want to add a partition.
  4. On the ALTER Table (ADB27C) panel, issue the ALTPART primary command to add or alter a partition of a table-based partitioned table, and press Enter.

    If the ALTPART command is not listed, the table is not partitioned.

  5. On the Alter Partitioned Table (ADB27CPV) panel, issue the ADD primary command to add a partition to the end of the table.
  6. Enter the limit key value for the new partition.
  7. Issue the NEXT command.
  8. On the ALTER Table (ADB27C) panel, issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  9. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.

Adding a partition to a table in a partition-by-growth (PBG) table space

Procedure

To add a partition to a table in a PBG table space:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the partitioned table to which you want to add a partition.
  4. On the ALTER Table (ADB27C) panel, issue the ADDPART primary command, and press Enter.

    The Partitions field is updated to reflect the change. Specifying a zero (ADDPART 0) resets the number of partitions to the original value.

  5. Issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  6. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.
Start of change

Inserting a partition into a table

Procedure

To insert a partition into a table:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the partitioned table where you want to insert a partition.
  4. On the ALTER Table (ADB27C) panel, specify the ALTPART primary command, and press Enter.

    If the ALTPART command is not listed, the table is not partitioned.

  5. On the Alter Partitioned Table (ADB27CPV) panel, issue the INS line command against the partition after which you want to insert a new partition, as shown in the following example:
    ADB27CPV  ----------------- DD1A Alter Partitioned Table---- Row 1 to 12 of 12  
    Command ===>                                                  Scroll ===> CSR   
                                                                                    
    New schema . : TS5771                                                           
    New name . . : TB1100                                                           
    
                                                                                   
    Commands: NEXT  ADD  ORIGINAL                                                     
    Line commands:  INS - Insert Partition                                         
                                                                                   
    Sel Part   Limit Key Value (Type a new value to add or alter)           Oper.  
    --- ------ -----------------------------------------------------------> ------
             1 '09999999999999999999999999999999'                                   
    INS      2 '10000000000000000000000000000000'                                   
             3 '19999999999999999999999999999999'                                   
             4 '20000000000000000000000000000000'                                   
             5 '29999999999999999999999999999999'                                   
             6 '39999999999999999999999999999999'                                   
             7 '49999999999999999999999999999999'                                   
             8 '59999999999999999999999999999999'                                   
             9 '69999999999999999999999999999999'                                   
            10 '79999999999999999999999999999999'                                   
            11 '89999999999999999999999999999999'                                   
            12 MAXVALUE                                                             
    ******************************* END OF DB2 DATA *******************************
  6. Enter the limit key value for the new partition, as shown in the following example:
    ADB27CPV  ----------------- DD1A Alter Partitioned Table---- Row 1 to 12 of 12  
    Command ===>                                                  Scroll ===> CSR   
                                                                                    
    New schema . : TS5771                                                           
    New name . . : TB1100                                                           
                                                                                    
    Commands: NEXT  ADD  ORIGINAL                                                     
    Line commands:  INS - Insert Partition                                         
                                                                                   
    Sel Part   Limit Key Value (Type a new value to add or alter)           Oper.  
    --- ------ -----------------------------------------------------------> ------   
             1 '09999999999999999999999999999999'                                   
    *        2 '10000000000000000000000000000000'                                   
             ? '11000000000000000000000000000000'                           INSERT
             3 '19999999999999999999999999999999'                                   
             4 '20000000000000000000000000000000'                                   
             5 '29999999999999999999999999999999'                                   
             6 '39999999999999999999999999999999'                                   
             7 '49999999999999999999999999999999'                                   
             8 '59999999999999999999999999999999'                                   
             9 '69999999999999999999999999999999'                                   
            10 '79999999999999999999999999999999'                                   
            11 '89999999999999999999999999999999'                                   
            12 MAXVALUE                                                             
    ******************************* END OF DB2 DATA *******************************
    Tip: If, after editing the limit key values, you decide that you want to reset all changes to the original values, use the RESET command.
  7. Issue the NEXT command.
  8. On the ALTER Table (ADB27C) panel, issue the NEXT command until the ALTER - Build Analyze and Apply Job (ADBPALT) panel is displayed.
  9. Choose options for building the WSL or batch job to implement the change, and press Enter to generate the job.
End of change
Start of change

Adding a foreign key

Procedure

To add a foreign key:

  1. On the DB2 Administration Menu (ADB2) panel, select option 1.
  2. On the System Catalog (ADB21) panel, select option T.
  3. On the Tables, Views, and Aliases (ADB21T) panel, issue the ALT line command against the table to be changed.
  4. On the ALTER Table (ADB27C) panel, specify the NEXT primary command, and press Enter.
  5. On the Alter Objects (ADB27CA) panel, specify the CFK (Create foreign key) line command next to the table where you want to add the foreign key.
     ADB27CA n ---------------------- DD1A Alter Objects ---------- Row 1 to 1 of 1 
     Command ===>                                                  Scroll ===> PAGE 
                                                                                    
     Commands: NEXT  - Generate jobs  ADD - Add objects                             
      ALTOPT  - Change alter options                                                
     Line commands:                                                                 
      A - Alter object  D - Delete  S - Select object  REL - Alter related          
      FK - Add FK-affected tables  RI - Add RI-related tables  E - Edit view DDL    
      ? - Show all line commands                                                    
                                                                                    
         Object   Object                                      RI RI  FK             
     Sel Qual     Name               Ty Info 1   Info 2     Rels Add Add Operation  
         *        *                  *  *        *             * *   *   *          
     --- -------> -----------------> -- -------> -------> ------ --- --- -----------
     CFK ADM001   TABLE01            TB KAWDCC   KAWSCC        0 NA  NA  MODIFY     
     ******************************* END OF DB2 DATA *******************************
  6. On the Alter Foreign Key Constraint (ADB21TAF) panel, specify the name of the constraint and the columns, and press Enter:
    ADB21TAF  -------------- DD1A Alter Foreign Key Constraint -------------- 
    Command ===>                                                                   
                                                                                   
    Commands: COLUMNS                                                              
                                                                                   
                                                                       More:     + 
     ALTER TABLE                                                                   
                                                                                   
     Table schema . . . ADM001    >                                                
     Table name . . . . TABLE01             >                                      
                                                                                   
     FOREIGN KEY                                                                   
     Constraint name  . . PRODUCT             > (? to look up existing constraints 
                                                                                   
      Columns                                                                       
             ( . . . . . . PRODNO, PRODNAME             
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                > )
                                                                                   
     REFERENCES    Table schema . . . ADM001    >                                  
                  Table name . . . .                     > (? to look up)         
                                                                                  
     ON DELETE  . . . . . RESTRICT  (RESTRICT, CASCADE, SET NULL, or NO ACTION)    
     ENFORCED . . . . . . YES       (Yes/No, default is Yes)   
     
    The ALTER TABLE statement is generated.
  7. If the Statement Execution Prompt (ADB2PSTM) panel is displayed, confirm that you want to execute the statement.

Results

The ALTER statement is run, and the foreign key is added.
End of change