Redian新闻
>
急问一个奇怪的sql server数据库问题
avatar
急问一个奇怪的sql server数据库问题# Database - 数据库
q*g
1
我用jdbc操作 sql server下的 database时,
遇到一个奇怪的现象:比如说一个简单的语句:
SELECT id, attr
INTO tempTB
FROM TB
WHERE (...)
ORDER BY attr
返回的tempTB 有的时候根本不是按照attr排序的,
确切地说,只是部分排序。比如说如果数据范围[1,1000],
输出的结果可能是 992 993,...1000, 876,877,878,。。
我多run几次,有时候又能输出正确排序后的结果。
有人遇到过这种情况么?到底怎么回事啊?
难道是sql server安装有问题?
但是我的机器刚刚重装过,以前用这个sql server的安装文件
也装过,从来没有碰到过这种问题。
avatar
k*e
2
When select from tempTB, you need to use order by attr to gurantee the
returned result is ordered.
avatar
q*g
3
Thanks!I've also found the reason from the website,
order by在select into 或者insert里面都是没用/unpredictable的:
Tables do not have an order. In other words, tables by definition are
logically an unordered set of rows. Using ORDER BY in a INSERT...SELECT or
SELECT...INTO does not mean that the data in the table is 'ordered'. The
order of rows which you see when you do a SELECT without an ORDER BY clause
is a undefined/arbitrary order chosen by the optimizer based on the physical
characteristics, indexes,

【在 k***e 的大作中提到】
: When select from tempTB, you need to use order by attr to gurantee the
: returned result is ordered.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。