数据库表是否在检索之前或之后进行排序? [英] Are database tables sorted before or after being retrieved?

查看:103
本文介绍了数据库表是否在检索之前或之后进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的游戏创建了一个存储在数据库上的高分表,但我想知道最好的做法是存储这样的表。
每当添加一个新的分数或者查询接收到的数据只是排序时,表格是否应该被排序?

I am creating a high scores table stored on a database for my game, but I was wondering the best practices are for storing such tables. Should the table be resorted each time a new score is added or should the data being received by a query just be sorted?

推荐答案

关系数据库中的行,例如MySQL,Oracle,PostgreSQL等不以任何顺序维护。在关系数据库的理论中,没有指定顺序返回结果集,除非查询包含 ORDER BY 子句。

Rows in a relational database such as MySQL, Oracle, PostgreSQL, etc. are not maintained in any order. In the theory of relational databases result sets are returned in no specified order unless the query contains an ORDER BY clause. Any ordering is (must be) applied each time the data is retrieved.

在某些情况下,实现可能以某种顺序存储数据,但不需要这样做。实际上,如果您对同一数据运行完全相同的查询两次,则无法保证数据将按相同的顺序返回。

Implementations may, in some cases, store the data in some order, but they are not required to do so. In fact, if you run the exact same query twice on the same data there is no guarantee that the data will be returned in the same sequence.

换句话说,不能对您的数据强加存储顺序,则只在执行查询时对结果集强加订单。

In other words, you cannot impose a storage order on your data, you impose order only on result sets at the time the query is executed.

这篇关于数据库表是否在检索之前或之后进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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