문제

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?

도움이 되었습니까?

해결책

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

ALTER TABLE table ADD COLUMN colname ... BEFORE othercolumn

다른 팁

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.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top