Results 1 to 4 of 4

Thread: Rename column

  1. #1
    Join Date
    Dec 2007
    Posts
    15

    Unanswered: Rename column

    Hi I'm new to DB2, currently our development server is version 8.2
    My question is how do I rename a column from x to y.

    I've read you can do
    ALTER TABLE a RENAME COLUMN x TO y;

    but it did not work. Is it even possible?

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    No, there is not a command to rename a column.

    You can however use the ALTOBJ Stored procedure to effectively change the column name.

    http://publib.boulder.ibm.com/infoce...n/r0011934.htm

    You can use the Control Center to "rename" the column and it generates the ALTOBJ statement to perform the work.

    Andy

  3. #3
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    Two other solutions: (depends on what you need this rename for):

    * rename the table, and create a view (with the old table name and with correct column names) referring the original table
    * add a column to the table, having the correct name. Then add insert & update triggers to make sure both columns always have identical content. (Or maybe just update existing rows to fill in the correct value for the new column.)
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Yet another alternative:
    1. add a new column with the correct name
    2. copy all values from old column to new column
    3. recreate all objects referring to the old table and point them to the new column (i.e. triggers, functions, views, etc.)
    4. drop old column


    p.s: I think the easiest way is the first approach listed by Peter.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •