Inserting new columns in the middle of a table?

后端 未结 6 491
陌清茗
陌清茗 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:46

    I know it's old subject (2009) but maybe it will help someone that still looks for an answer. In MySQL, it works 2 add a column anywhere in the table.

    ALTER TABLE `tablename` ADD `column_name1` TEXT NOT NULL AFTER `column_name2`;
    

    This is 2 enter a text column, but u can set whatever properties u want for the new column, just make sure u write them with caps.

    I found it with Xampp, MySQL admin, when i used it 2 insert a column in the middle of a MySQL table.

    Hope it helps.

提交回复
热议问题