是否有“默认按列排序"?在 SQL Server 中? [英] Is there a "Default Order By Column" in SQL Server?

查看:24
本文介绍了是否有“默认按列排序"?在 SQL Server 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行像 SELECT col1, col2, col3 FROM table 这样的查询时,它会按主键升序排序.

When I execute a query like SELECT col1, col2, col3 FROM table, it gets sorted by the primary key ascending.

我只是想知道是否有一种方法可以指定不同的列,例如 ORDER BY CreatedDate DESC 如果没有 Order By 子句?

I'm just wondering if there is a way to specify a different column, like ORDER BY CreatedDate DESC if there is no Order By clause?

我对此表示怀疑(因为它非常不直观,但无论如何还是想知道.

I doubt it (since it would be very unintuitive, but just wondering anyway.

推荐答案

没有.您看到的任何排序都是查询优化器策略的产物.关系理论禁止对任何数据集进行任何隐式排序.

No. Any ordering you see is an artifact of the query optimizer's strategy. Relational theory forbids that there is any implicit ordering of any set of data.

您甚至不能指望下次对同一查询使用相同的顺序,因为优化器策略取决于上下文和可能发生变化的数据.

You can't even count on the same ordering next time for the same query because the optimizer strategy depends on the context and the data which might change.

这篇关于是否有“默认按列排序"?在 SQL Server 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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