重新排序列的简单方法?

发布于 2024-09-30 06:16:36 字数 113 浏览 2 评论 0原文

我正在研究数据库。在大多数表上,列顺序不是我所期望的,我想更改它(我有权限)。例如,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

木緿 2024-10-07 06:16:36

使用 ALTER TABLE ... MODIFY COLUMN 语句。

ALTER TABLE table_name MODIFY COLUMN misplaced_column INT(11) AFTER other_column;

Use an ALTER TABLE ... MODIFY COLUMN statement.

ALTER TABLE table_name MODIFY COLUMN misplaced_column INT(11) AFTER other_column;
佼人 2024-10-07 06:16:36

这是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;

策马西风 2024-10-07 06:16:36

既然您提到了 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.

清风不识月 2024-10-07 06:16:36
ALTER TABLE `table`
CHANGE COLUMN `field` `field` 
INT(11) AFTER `field2`;
ALTER TABLE `table`
CHANGE COLUMN `field` `field` 
INT(11) AFTER `field2`;
苦妄 2024-10-07 06:16:36

在 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).

蹲在坟头点根烟 2024-10-07 06:16:36

另一种方法是:

#CREATE TABLE original (
#    id INT
#    name TEXT
#    etc...
#);

CREATE TABLE temp (
    name TEXT
    id INT
    etc...
);

INSERT INTO temp SELECT name, id FROM original;

DROP TABLE original;

RENAME TABLE temp TO original;

Another approach is to:

#CREATE TABLE original (
#    id INT
#    name TEXT
#    etc...
#);

CREATE TABLE temp (
    name TEXT
    id INT
    etc...
);

INSERT INTO temp SELECT name, id FROM original;

DROP TABLE original;

RENAME TABLE temp TO original;
微凉 2024-10-07 06:16:36

SQL Maestro for MySQL 提供了重新排序字段的工具以及 GUI,不幸的是它不是拖放操作。

  1. 打开表视图
  2. 打开“属性”选项卡
  3. 单击侧栏中的“重新排序字段”
  4. 单击要移动的字段,然后单击向上或向下绿色箭头
  5. 单击“确定”提交数据库更新

可能还有其他程序和实用程序可以执行此操作。我通过搜索发现了这个帖子,所以我想我会与其他人分享我发现的内容。

SQL Maestro for MySQL offers tools to reorder fields as well with a GUI unfortunately it is not a drag and drop.

  1. Open table view
  2. Open Properties tab
  3. Click Reorder fields from the sidebar
  4. Click on the field you want moved and then click the up or down green arrows
  5. Click OK to submit database update

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.

情话难免假 2024-10-07 06:16:36

新版本的简单方法:

  1. 打开要重新排序的表。
  2. 转到结构选项卡。
  3. 选择移动列链接。
  4. 根据需要对列重新排序。

Easy method for the newer version:

  1. Open the table you want to reorder.
  2. Go to structure tab.
  3. Chose move column link.
  4. Reorder the columns as you wish for.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文