Results 1 to 6 of 6

Thread: Alter Table

  1. #1
    Join Date
    Feb 2003
    Location
    Tallahassee, Florida USA
    Posts
    43

    Alter Table

    Hi all,
    I am really new to DB2
    and I need to know if it is possible to alter a field in a table to be auto increment.
    The table already have data in it.
    Thank you in advance.

  2. #2
    Join Date
    Feb 2003
    Location
    Tallahassee, Florida USA
    Posts
    43
    Never mind, it is not possible.
    I will have to drop the table and recreate it and of course lose all the data.

    Thanks...

  3. #3
    Join Date
    Feb 2003
    Posts
    1,048
    Create a temporary table to hold the data, drop and recreate the table with an autoincrement field, and then populate the data from the temporary table.

  4. #4
    Join Date
    Feb 2003
    Location
    Tallahassee, Florida USA
    Posts
    43
    The problem is that the table already
    has values; if I recreate the table and
    populate the data in it again I will have new ids;
    sorry I did not mention that the ids in the table are being
    used as FK in another table.

    I appreciate your help

  5. #5
    Join Date
    Feb 2003
    Posts
    1,048
    I don't know what the command is for DB2, but there should be a command to allow you to temporarily insert specified values into the field. You will need to drop the foreign key constraint on the other table and then recreate it at the end.

  6. #6
    Join Date
    Feb 2003
    Location
    Tallahassee, Florida USA
    Posts
    43
    In DB2; If you want to drop a field or even rename it you will have to drop the TABLE and recreate it!!! (strange)
    At least this is what I found after searching and asking around;
    (I hope that you have a better solution).

    We took care of the problem using ASP code because the original tables are in MSSQL 2000 and we need to move them to DB2. (I do not like this idea but it works).

Posting Permissions

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