如何在现有表格的特定位置插入列? [英] How to insert columns at a specific position in existing table?

查看:128
本文介绍了如何在现有表格的特定位置插入列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个有85列的表格,但是我错过了一列.错过的栏应该是第57栏.我不想删除该表并再次创建它.我希望编辑该表并在第57个索引中添加一列.

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 edit that table and add a column in the 57th index.

我尝试了以下查询,但在表末尾添加了一列.

I tried the following query but it added a column at the end of the table.

ALTER table table_name
Add column column_name57 integer

如何将列插入特定位置?

How can I insert columns into a specific position?

推荐答案

ALTER TABLE默认情况下在表的末尾添加新列.使用AFTER指令将其放置在表格中的某个位置:

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

来自mysql文档

要在表行中的特定位置添加一列,请使用FIRSTAFTER col_name .默认为最后添加该列.您还可以在CHANGEMODIFY操作中使用FIRSTAFTER对表中的列进行重新排序.

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

我为PostgreSQL搜索了此文件,但

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

这篇关于如何在现有表格的特定位置插入列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆