I have a query that I execute on SQL Connection and make a reader from SqlCommand.ExecuteReader. I'm doing a simple selection * from the table * I am not using any order, but the results from the query are always returned in one order when run in the management studio. 1 2 3 4 But when I do a reader Read () order is not the same. I think a random record is being drawn 3 2 4 1 Anyone can know why this could happen?
If you do not say ORDER BY, ADO The Net is free to return the rows in any order. Why do you complain?
People often mistakenly believe that the sequence of rows will be clustered ... or if they use a group, then it will be in this order ..
< Strong> Sometimes these assumptions always depend on implementation details and specific execution plans.
The only way to get the guarantee order is by order to use your result, something else is wrong, or you do not care about the order. BTW, it does not always mean a performance hit for sorting, the SQL server is very smart and if it knows that the rows have already been sorted (such as it's your Order reads from the index based on the call), it will not do anything.
No comments:
Post a Comment