Matt Jarvis wrote:
> When a query is run against a table, are the records, by default,
> returned in natural order?
>
> If I run:
>
> select * from MyTable
>
> shouldn't they be returned in the order they were added?
>
> I am seeing records apparently out of order based on an auto-increment
> field, but they could/would be fine if for some reason they were
> returned in non-natural order.


I learned back in SQL Server 2007 days that you couldn't rely on
physical order.  The thing that helped me understand this was the idea
that "empty/vacated rows" could be filled in with newer data, so imagine
rows with matching PKs 1-10 entered initially.  Rows 3 & 6 were deleted,
and 2 new rows added could be physically placed in those spots, despite
having PKs 11 and 12 (using this example).

Use the PK (if integer) for natural order, or what I do with tables now
is have a column called TADDED where it's the date/time stamp when the
row was inserted.  That way, you can count on that regardless of
INT/GUID/STRING primary keys.

-- 
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to