如何以永久的方式对 MYSQL 表进行排序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19824928/
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
How to sort a MYSQL table in a permanent way?
提问by CyberBoy
I am a having a table with column Symbol and Weight(only two Column) . I need to sort table according to weight of the symbols, that i can do by
我有一个表,其中包含 Symbol 和 Weight(只有两列)列。我需要根据符号的权重对表格进行排序,我可以这样做
SELECT symbol, weight FROM symbols ORDER BY weight DESC
but this wont change my table, but it will give me a sorted output(temporary).
但这不会改变我的表,但它会给我一个排序的输出(临时)。
I want to sort table permanently. How can i do that?
我想永久排序表格。我怎样才能做到这一点?
回答by Jannic Beck
You can do this with ALTER TABLE
你可以用 ALTER TABLE 做到这一点
f.e.
铁
ALTER TABLE tablename ORDER BY columnname ASC;.
but be aware that the table does not remain in this order after inserts and deletes
但请注意,插入和删除后,表不会保持此顺序
回答by bijiDango
Actually you can add a new integer column sort
and set it as primary key. If you already has primary key, just change that to uniquewould be OK.
实际上,您可以添加一个新的整数列sort
并将其设置为主键。如果您已经有主键,只需将其更改为unique就可以了。