假设我有一个表(假设有 50 行,50 列),我偶尔需要对其进行微小的编辑。虽然我意识到我可以(也许你们中的一些人会告诉我我应该这样做)使用查询来执行此操作,但我喜欢使用数据库管理程序(如 Sequel Pro)来手动进行更改。
所以我有两个问题:
当您执行查询而不指定显示结果的顺序时,它将遵循它在数据库中保存的顺序。有什么方法可以更改该顺序(不是结果的顺序,而是表本身的顺序)而无需手动切换行?
此外,是否有任何方法可以自动对字段在表中显示的方式(列顺序)进行排序?
我知道我应该只使用查询来更改值,但是(imo)如果表足够小,我发现在像 Sequel Pro 这样的程序中找到行和列并以这种方式更改它会更容易。
另外,如果我的方法完全错误,请告诉我
最佳答案
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
ALTER TABLE name ORDER BY something
它有一些严重的警告,并且不要依赖它们做任何其他事情,然后可能会在排序时获得一些非常小的性能增益,只是为了方便您使用运行任意选择而无需排序的工具:
ORDER BY enables you to create the new table with the rows in a specific order. Note that the table does not remain in this order after inserts and deletes. This option is useful primarily when you know that you are mostly to query the rows in a certain order most of the time. By using this option after major changes to the table, you might be able to get higher performance. In some cases, it might make sorting easier for MySQL if the table is in order by the column that you want to order it by later.
关于mysql - 对 MySQL 表的字段进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3268520/