在每个执行内部连接以随机顺序返回结果 [英] On each execution innerjoin return result in random order

查看:74
本文介绍了在每个执行内部连接以随机顺序返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的团队

我正面临一个有线问题,每次执行时,InnerJoin会以随机顺序返回结果。

这也发生在SQL 2008R2和2012上。



两个内连接列都有(相同)数据类型NUMERIC(18,0)



可能的原因是什么?

这是我的样本查询



Dear team
I am facing an wired issue, where On each execution InnerJoin return result in random order.
This occurred on SQL 2008R2 and 2012 also.

Both inner join column have (same) datatype NUMERIC(18,0)

what could be possible reason ?
here is my sample query

SELECT info.col1, 
info.col2, info.col3, info.col4
FROM table1 AS info INNER JOIN tavle2 AS pln ON  pln.col2 =info.col6 WHERE info.col6 = 'I00262'





< b>我尝试了什么:



1.我检查了两列的数据类型(相同)



What I have tried:

1. I have check datatypes of both columns (which are same)

推荐答案

您已假设数据库表具有开始的顺序。他们没有。表中的记录可以随时以任何顺序返回。这归结为数据来自SQL Server的位置。这意味着直接来自磁盘,缓存页面,受到其他一些操作的影响,你有什么。它们可以按随机顺序写入数据库。有很多因素在起作用。



我有代码将大量数据记录到表中以便进行调试。当代码写入时(时间戳),记录都按特定顺序写入,但是当您稍后查询数据库时,您发现记录都混乱了。



当您向SELECT查询添加ORDERBY子句时,只保证时间记录具有任何类型的顺序。除此之外,假设它们无序。
You've made the assumption that database tables have an order to begin with. They don't. The records from a table can be returned in any order at any time. This comes down to where the data came from in the SQL Server. This means coming straight from disk, from cache pages, affected by some other operations going on, what have you. They could be written to the database in random order. There are a lot of factors in play.

I've got code that logs a lot of data to a table for debugging purposes. The records are all written in a specific order when the code writes them (timestamped) but when you query the database later you find the records are all jumbled up.

The only time records are guaranteed to have any kind of order at all is when you add an ORDERBY clause to your SELECT query. Other that that, assume they are out of order.


这篇关于在每个执行内部连接以随机顺序返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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