MySQL 使用 phpmyadmin 重新排列列的顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6219374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL re-arranging order of columns with phpmyadmin
提问by karto
Any help on re-ordering the columns in MySQL using phpMyAdmin? Is it called cardinality? I have created tables, but need to re-arrange the order of the columns due to an export script i have. It exports based on the arrangements. E.g. I want columns:
使用 phpMyAdmin 重新排序 MySQL 中的列有什么帮助吗?它被称为基数吗?我已经创建了表,但由于我有一个导出脚本,需要重新排列列的顺序。它根据安排出口。例如我想要列:
Apple | Cherry | Banana
changed to:
变成:
Apple | Banana | Cherry
采纳答案by King Skippus
Use the ALTER TABLE with MODIFY COLUMN command. Something like:
将 ALTER TABLE 与 MODIFY COLUMN 命令一起使用。就像是:
ALTER TABLE foo MODIFY COLUMN Hobby VARCHAR(20) FIRST;
I don't know whether or not there's a GUI way to do it in phpmyadmin, but normal SQL queries should work, too.
我不知道在 phpmyadmin 中是否有 GUI 方法可以做到这一点,但普通的 SQL 查询也应该可以工作。
回答by DisgruntledGoat
phpMyAdmin has finally included this feature in the most recent version (4.0 and up).
phpMyAdmin 终于在最新版本(4.0 及更高版本)中包含了此功能。
Go to the "Structure" view for a table, click the Change button on the appropriate field, then under "Move column" select where you would like the field to go.
转到表的“结构”视图,单击相应字段上的“更改”按钮,然后在“移动列”下选择您希望该字段移动的位置。
回答by BeNice
OP asked how to change column order in phpMyAdmin.
OP 询问如何更改phpMyAdmin 中的列顺序。
NB:phpMyAdmin keeps making changes but, as of Nov 2019, this is still correct.
注意:phpMyAdmin 不断进行更改,但截至2019 年 11 月,这仍然是正确的。
1) Click on "Structure".
1) 点击“结构”。
2) Next click on "Move columns" at the bottom.
2)接下来点击底部的“移动列”。
3) and voila just drag and drop!(Very modern for dear old myPhpAdmin!)
3)瞧,只需拖放即可!(对于亲爱的老 myPhpAdmin 来说非常现代!)
回答by Halcyon
To reorder columns, pop-up a query window and use the statement:
要对列重新排序,请弹出一个查询窗口并使用以下语句:
ALTER TABLE ... MODIFY COLUMN ... FIRST|AFTER ...
Unfortunately you will have to retype the entire column definition. See http://dev.mysql.com/doc/refman/5.1/en/alter-table.htmlExample:
不幸的是,您将不得不重新键入整个列定义。参见http://dev.mysql.com/doc/refman/5.1/en/alter-table.html示例:
ALTER TABLE t MODIFY COLUMN cherry VARCHAR(255) NULL AFTER banana;
May vary depending on your MySQL version, but this syntax appears to work since version 3.23.
可能因您的 MySQL 版本而异,但此语法自 3.23 版起似乎有效。
回答by Johan
Unfortunately, you will have to (1) pop up a query window, and (2) respecify the attributes of each column you rearrange. For example:
不幸的是,您将不得不 (1) 弹出一个查询窗口,以及 (2) 重新指定您重新排列的每一列的属性。例如:
ALTER TABLE test.`new table`
MODIFY COLUMN cherry unsigned int(10) NOT NULL AUTOINCREMENT PRIMARY KEY
AFTER banana
Table layout before change:
更改前的表格布局:
`apple` varchar(45) NOT NULL,
`cherry` int(10) unsigned NOT NULL AUTO_INCREMENT,
`banana` varchar(45) NOT NULL
Table layout after change:
更改后的表格布局:
`apple` varchar(45) NOT NULL,
`banana` varchar(45) NOT NULL,
`cherry` int(10) unsigned NOT NULL AUTO_INCREMENT