根据主键在表上按正确顺序插入行。 [英] Insert row in proper order on table based off of primary key.

查看:204
本文介绍了根据主键在表上按正确顺序插入行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢能够去phpmyadmin,看到我的行排序。
是否有一个简单的方法可以通过它的主键将行插入正确的顺序?

解决方案


除非指定ORDER BY,否则不保证首先返回什么行



但是实际上,订单通常匹配聚集索引
order,并且在调用之间不会有所不同。不要依赖此行为。


MySQL的LIMIT关键字保证返回数据的顺序吗?


没有默认排序顺序。即使表具有聚集的
索引,也不能保证以该顺序获得结果。如果你想要一个特定的订单,你
必须使用order by子句。


SQL处理默认排序顺序的最佳做法


只需插入数据;表不是从根本上排序。表结果的唯一顺序是在您在select语句中自己定义的时候。


是否可以将数据插入表格的中间部分使用INSERT命令?


你不能。没有这样的事情。



更准确地说,在MyISAM引擎中,当前顺序是任何当执行最后一个ALTER TABLE ORDER BY时的
顺序,



InnoDB只是根据需要对表格进行排序。


查看当前表格顺序

$ b但是请注意上面的另一个海报的建议:
中没有ORDER BY子句返回的行是任意的,
可能更改,恕不另行通知。最好是尽可能修改你的表


反转没有ORDER BY的MySQL表的自然顺序?

....和maaany更多。


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 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.

这篇关于根据主键在表上按正确顺序插入行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆