SQL - how to rename column in DDS table

By kimot, 27 December, 2022

On IBM i you cannot use ALTER TABLE table_name RENAME COLUMN column1 TO column2 with a DDS table.

You have to create new column first and then copy data between columns and finally delete old one:

ALTER TABLE table_name ADD COLUMN new_column VARCHAR(10);      
UPDATE table_name SET new_column = old_column;
ALTER TABLE table_name DROP COLUMN old_column;

If you will execute this command in "Run SQL Scripts" utility, you can get message SQL0952 Processing of the SQL statement ended.  Reason code 10 when dropping old_column

You can try to set automatic reply in "Run SQL Scripts" :

BEGIN
  IF NOT EXISTS (
    SELECT * 
      FROM QSYS2.REPLY_LIST_INFO 
     WHERE MESSAGE_ID='CPA32B2') THEN
    CALL QCMDEXC('ADDRPYLE SEQNBR(5000) MSGID(CPA32B2) RPY(I)'); 
  END IF;
    CALL QCMDEXC('CHGJOB INQMSGRPY(*SYSRPYL)');
END;

Or you can do this step on green screen STRSQL where you can set "I" as Reply

Change of file TABLE_NAME may cause data to be lost. (C I)                     
                                                                               
                                                                               
Type reply, press Enter.                                                       
  Reply . . .                          I