重新排序列的简单方法?
我正在研究数据库。在大多数表上,列顺序不是我所期望的,我想更改它(我有权限)。例如,primary_key 的 id 列很少是第一列!
有没有一种简单的方法可以使用 phpMyAdmin 移动列?
I'm working on a database. On most of the tables, the column order is not what I would expect, and I would like to change it (I have the permission). For example, the primary_key's id
columns are rarely the first column!
Is there an easy method of moving columns with phpMyAdmin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用 ALTER TABLE ... MODIFY COLUMN 语句。
Use an ALTER TABLE ... MODIFY COLUMN statement.
这是sql查询
ALTER TABLE table_name MODIFY COLUMN Misplaced_column 列定义 AFTER other_column;
这里的Column-definition是完整的列定义。如果您使用 phpmyadmin,要查看列定义,请单击“结构”选项卡。然后单击所需列上的更改链接。然后,无需修改任何内容,单击“保存”。它会告诉你sql。复制 sql 并在末尾添加 *AFTER other_column* 。这将是全部。
如果您想将 *misplaced_column* 带到第一个位置,那么
ALTER TABLE table_name MODIFY COLUMN missplaced_column 列定义优先;
Here is the sql query
ALTER TABLE table_name MODIFY COLUMN misplaced_column Column-definition AFTER other_column;
Here in Column-definition is full column definition. To see the column definition if you are using phpmyadmin click on structure tab. Then click on change link on desired column. Then withour modifyig any things click save. It will show you the sql. Copy the sql and just add *AFTER other_column* at the end. It will be all.
If you like to bring the *misplaced_column* to the first position then
ALTER TABLE table_name MODIFY COLUMN misplaced_column Column-definition FIRST;
既然您提到了 phpMyAdmin,现在有一种方法可以在最新版本(4.0 及更高版本)中对列进行重新排序。
转到表的“结构”视图,单击相应字段上的“编辑”(或“更改”)按钮,然后在“移动列”下选择您想要字段移动的位置。
Since you mention phpMyAdmin, there is now a way to reorder columns in the most recent version (4.0 and up).
Go to the "Structure" view for a table, click the Edit (or Change) button on the appropriate field, then under "Move column" select where you would like the field to go.
在 phpMyAdmin 版本 3.5.5 中,转到“浏览”选项卡,然后将列拖动到您的首选位置以重新排序(例如,如果您有名为 A、B、C 的列,您所需要做的就是将 C 列拖动到 A 和B 将其重新排序为 A、C、B)。
In phpMyAdmin version 3.5.5, go to the "Browse" tab, and drag the columns to your preferred location to reorder (e.g. if you have columns named A,B,C, all you need to do is drag column C between A and B to reorder it as A,C,B).
另一种方法是:
Another approach is to:
SQL Maestro for MySQL 提供了重新排序字段的工具以及 GUI,不幸的是它不是拖放操作。
可能还有其他程序和实用程序可以执行此操作。我通过搜索发现了这个帖子,所以我想我会与其他人分享我发现的内容。
SQL Maestro for MySQL offers tools to reorder fields as well with a GUI unfortunately it is not a drag and drop.
There are probably other programs and utilities to do this as well. I found this thread from a search so I thought I would share what I found for others.
新版本的简单方法:
Easy method for the newer version: