Is the exact matching of row sorting guaranteed when inserting from an already sorted table? Are two selects guaranteed to return the same order?

declare @OUTPUT table ( [row1] int, [row2] varchar(255), [row3] int ) INSERT INTO @OUTPUT SELECT TOP 1000 [row1] ,[row2] ,[row3] FROM table ORDER BY [row1] select * from @OUTPUT select * from @OUTPUT 
  • @SomeName, of course not, because the relational model on which SQL is based says nothing about the order of tuples. Even in the new version of the same DBMS (or with a different physical organization of tables, etc.), the results may differ. - avp

1 answer 1

Not. But this is very likely, especially with a clustered index. If sorting is needed, use order by.