简体   繁体   English

向具有特定序号位置的 DB2/400 表添加一列

[英]Add a column to a DB2/400 table with a specific ordinal position

AS400/iSeries/System-i/whatever 上是否有 SQL 命令可以将列添加到表的特定顺序位置,或将现有列移动到不同位置?

IBM i 7.1 现在允许您在另一列之前添加一列。

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:不。 ALTER TABLE语句将允许您向表中添加一列,但是,根据文档:

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.也就是说,如果最初有 n 列,则添加的列是第 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.使用RENAME语句重命名表。
  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.使用 INSERT SELECT 用重命名的表中的数据填充新表。
  4. When you're sure the data is intact, you can drop the renamed version of the table.当您确定数据完好无损时,您可以删除表的重命名版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM