SQL Server如何找出查询执行结果集中的记录顺序?
我试图做它的正面或反面,但发现自己在挠挠头。当我更改字段时,我选择的顺序也会更改。当我使用a执行以下SQL时,SELECT *
我得到的记录相同,但顺序却大不相同。
SELECT TOP (900)
AD.ATTACHMENTID,
AD.NAME,
AD.ISINLINE,
AD.INSERTEDDATETIME,
ATMT.ATTACHMENTBLOB,
U.UFID
FROM ATTACHMENTDETAIL AD WITH (NOLOCK)
INNER JOIN MESSAGEATTACHMENT MA ON MA.ATTACHMENTID = AD.ATTACHMENTID
INNER JOIN ATTACHMENT ATMT ON ATMT.ATTACHMENTID = AD.ATTACHMENTID
INNER JOIN MESSAGE MSG ON MSG.ID = MA.MESSAGEID
INNER JOIN MESSAGEDETAIL MD ON MD.MESSAGEID = MA.MESSAGEID
INNER JOIN [USER] U ON U.ID = MD.USERID
LEFT OUTER JOIN XmlExtractionMapping XM ON MA.MESSAGEID = XM.MessageId
WHERE AD.FILEBOXTOKEN IS NULL
AND (XM.XMLEXTRACTIONDATE IS NOT NULL OR
(MSG.MESSAGESOURCEID = 1 AND MD.FolderId <> -4))
AND AD.ISINLINE = 'FALSE'
RCSI?请解释...
—
kacalapy 2012年
RCSI =读取提交的快照隔离。见stackoverflow.com/questions/816650/...
—
阿龙贝特朗
如果没有
—
Nick Chammas 2012年
ORDER BY
子句,SQL Server(和任何其他RDBMS)将执行任何操作。
NOLOCK
-您会看到各种不使用它的原因。对于后者,请参见sqlblog.com/blogs/aaron_bertrand/archive/2009/10/11/…–