|
Posted by Hugo Kornelis on 02/01/06 00:21
On 30 Jan 2006 19:57:03 -0800, Doug wrote:
>
>>> I've used cursors all the time without an order by function.my bad. <<
>
>
>>That will give you random results, based on the internal state of the
>database at the time of the query.
>
>Really???? Wow. Could you point me to the documentation that states
>that you will get a different set of data for your cursor if you don't
>use an order by statement?
>
>So which is it? Are we set based, or are we "set based, but sets are
>different depending on whether they are in order and in a cursor."
Hi Doug,
We are set based. And a set in a relational database is a collection of
rows with no implied order.
A cursor is not a set - it is an operation to turn a set into a series
of rows, with implied order. If you use ORDER BY in the DECLARE CURSOR
statement, the order of the rows in the cursor is defined. Without an
ORDER BY, the optimizer is free to choose an order in which the rows
will be fed to the cursor. And there is no guarantee that the same order
will be used the next time you execute the same statement.
--
Hugo Kornelis, SQL Server MVP
[Back to original message]
|