How to insert columns at a specific position in existing table?

前端 未结 8 2082
野趣味
野趣味 2020-12-25 09:54

I created a table with 85 columns but I missed one column. The missed column should be the 57th one. I don\'t want to drop that table and create it again. I\'m looking to ed

相关标签:
8条回答
  • 2020-12-25 10:48
    ALTER TABLE table_name ADD COLUMN column_name integer
    
    0 讨论(0)
  • 2020-12-25 10:49

    ALTER TABLE by default adds new columns at the end of the table. Use the AFTER directive to place it in a certain position within the table:

    ALTER table table_name
        Add column column_name57 integer AFTER column_name56
    

    From mysql doc

    To add a column at a specific position within a table row, use FIRST or AFTERcol_name. The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table.

    http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

    I googled for this for PostgreSQL but it seems to be impossible.

    0 讨论(0)
提交回复
热议问题