且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL-按ID自动排序不起作用

更新时间:2023-01-29 23:35:00

问:有什么方法,如何设置表以仅通过"ID"列自动对所有新添加的项目进行排序?

Q: Is there any way, how to set my table for automatic ordering all newly added projects only by the 'ID' column?

A:MySQL表中没有自动排序". (某些存储引擎,例如InnoDB,是索引组织的"结构,并按群集键按顺序存储行.)但是,该组织未定义或指定SELECT语句返回的行的顺序.

A: There is no "automatic ordering" in a MySQL table. (Some storage engines, such as InnoDB, are "index organized" structures, and do store rows in order by the cluster key.) But this organization does not define or specify the order of rows returned by a SELECT statement.

在SELECT语句上没有ORDER BY子句,则MySQL服务器可以按其选择的 any 顺序返回行.不能保证任何自动"或默认"顺序.

Without an ORDER BY clause on a SELECT statement, then the MySQL server can return rows in any order it chooses to. There is no guarantee of any "automatic" or "default" ordering.

当我们运行不带ORDER BY子句的SQL SELECT语句时,我们确实观察到行倾向于以一致的顺序返回.这种行为不能得到保证,也不是自动的".

When we run a SQL SELECT statement without an ORDER BY clause, we do observe that rows tend to be returned in a consistent order. This behavior isn't guaranteed, and it isn't "automatic".

我们观察到的这种一致的排序"行为是由于MySQL服务器对一致的数据集执行了一致的操作集.

This consistent "ordering" behavior we observe is due to the MySQL server performing a consistent set of operations, on a consistent set of data.

执行ALTER TABLE语句以重建整个表不是 解决自动排序"问题的方法.

Performing an ALTER TABLE statement to rebuild the entire table is not the solution to the "automatic ordering" issue.

如果您希望MySQL服务器按特定顺序返回行,则解决方案是在SELECT语句中添加ORDER BY子句.

If you want the MySQL server to return rows in a specific order, then the solution is to add an ORDER BY clause to the SELECT statement.

执行SELECT语句的客户端可以***地对其检索的行进行任何操作.客户端可以执行诸如过滤,排序等之类的操作,以得出在用户界面中返回的内容.

The client that executes the SELECT statement is free to do whatever it wants with the rows it retrieves. The client can perform operations such as filtering, ordering, or whatever, to come up with what gets returned in the user interface.

某些客户端(如mysql命令行)未实现用于过滤"或排序"行的任何功能,因此,客户端指定返回行的顺序的唯一方法是ORDER BY子句声明本身. (MySQL命令行客户端以与检索到的顺序相同的顺序在用户界面中返回行.)

Some clients (like the mysql command line) don't implement any functions for "filtering" or "ordering" rows, so the only way for the client to specify an order that rows should be returned in is the ORDER BY clause on statement itself. (The MySQL command line client returns rows in the user interface in the same order that they are retrieved.)

我希望phpMyAdmin做同样的事情,它以与从MySQL服务器返回的行相同的顺序显示行.

I expect that phpMyAdmin does the same thing, it displays the rows in the same order that they are returned from the MySQL server.