The article shows the danger of trying something out with a small set of data, and expecting the same results with a large set of data because of an assumption the only influence on the result is the volume of data. We have all done this to some extent, and no doubt we will all make unwarranted assumptions again in the future...
In the article, the small set of data was contained in one database extent. With a large set of data, multiple extents will be used. When the table grows, the next available extent will be allocated to the table. If delete or drop activity has taken place to other tables in the database, the 'next available extent' may be physically closer to the start of the file than other extents already allocated to the table.
If we then ask SQL to retrieve all data from the table, the data will be retrieved in physical extent sequence, not in allocated extent sequence. This could easily result in data that has been inserted in an extent that has been allocated recently being presented earlier than data that is older but which is located in an extent that is physically further away in the file.
The same principle applies to data that is retrieved by an index, regardless of if the index is clustered or unclustered. All that a clustered index guarantees is that the sequence of rows stored in the table matches the index definition. It does not grarantee that the sequence of extents making up the table or the index will be stored in a physical order that matches the index definition. Therefore if you have a large and growing table with a cluster index on colum TABID, and that all tables in the database are subject to insert and delete activity, you can legitimately get a non-ordered result set with a SELECT TABID FROM TABLE.
The likelyhood of result sets being non-ordered greatly increases if you have multiple files in the file group, but can occur with just a single file filegroup.
The only way to guarantee the sequence of rows in a result set is to use a ORDER BY clause. This forces SQL to return the rows to you in the sequence you desire. SQL will decide itself if it is more efficient to follow the sequence of an index to get your result set, or if it is more efficient to collect all rows in a scan of the database then sort them before returning them to you.
If you do not specify an ORDER BY, then SQL will assume you do not care about the sequence in the result set, and will get your data in the fastest possible way.
Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.
When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara