Question

Is there an SQL command on the AS400/iSeries/System-i/whatever to add a column to a table in a specific ordinal position, or moving an existing column to a different position?

Was it helpful?

Solution

IBM i 7.1 now allows you to add a column in front of another.

ALTER TABLE table ADD COLUMN colname ... BEFORE othercolumn

OTHER TIPS

No. The ALTER TABLE statement will allow you add a column to a table, but, according to the documentation:

The new column is the last column of the table; that is, if initially there are n columns, the added column is column n+1.

If you'd like to change the order of columns in your table, your best bet is to:

  1. Use the RENAME statement to rename the table.
  2. Recreate the table, with its original name, with the columns in the order that you want.
  3. Use an INSERT SELECT to populate the new table with the data from the renamed table.
  4. When you're sure the data is intact, you can drop the renamed version of the table.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top