Inserting new columns in the middle of a table?

后端 未结 6 505
陌清茗
陌清茗 2020-12-20 14:29

When one uses \"ALTER TABLE tab ADD col\", the new column gets added to the end of the table. For example:

TABLE: TAB
COL_1 COL_2 COL_4

ALTER TABLE TAB ADD          


        
6条回答
  •  太阳男子
    2020-12-20 14:50

    By default, columns are only added at the end.

    To insert a column in the middle, you have to drop and recreate the table and all related objects (constraints, indices, defaults, relationships, etc).

    Several tools do this for you, and depending on the size of the table, this may be an intensive operation.

    You may also consider creating views on the table that display columns in the order of preferrence (overriding the actual order in the table).

提交回复
热议问题