Insert row in proper order on table based off of primary key.
I like being able to go to phpmyadmin and seeing my rows ordered. Is there an easy way to insert a row into the correct order by it's primary开发者_如何学Go key?
There is no order you can rely on.
Unless you specify ORDER BY, there are no guarantees about what rows will be returned first.
But in practice, the order will typically match the clustered index order, and will not vary between calls. Don't rely on this behaviour.
Does MySQL's LIMIT keyword guarantee order of returned data?
There is no default sort order. Even if the table has a clustered index, you are not guaranteed to get the results in that order. You must use an order by clause if you want a specific order.
SQL best practice to deal with default sort order
Just insert the data; tables are not fundamentally ordered. The only ordering of table results occurs when you define it yourself in your select statement.
Is it possible to insert data into the mid section of a table using the INSERT command?
You can't. There is no such thing.
To be precise: in MyISAM engine, current order is whatever the order was when the last ALTER TABLE ORDER BY was performed, modified by all the deletions and insertions since.
InnoDB just sorts the tables as it wishes.
view current table order
However be aware of the advice from another poster above: the order in which rows are returned without an ORDER BY clause is arbitrary and may change without notification. It would be best to amend your table if at all possible.
Reverse the “natural order” of a MySQL table without ORDER BY?
.... and maaany more.
精彩评论