SQL2000: Default order of columns when selecting from syscolumns
I'm running the following query:
select syscolumns.name
from syscolumns,sysobjects
where
syscolumns.id = sysobjects.id and
sysobjects.name='TABLE_NAME'
What could be the reason that in one system the columns are returned alphabetically and on another, they are returned in the order that the columns were added to the table?
I know I shouldn't rely on the default order, and I should use ORDER BY, but I want to know why is开发者_高级运维 this so. Collation?
Thanks!
There is no default order that you could "rely upon" - unless you explicitly specify an ORDER BY
.
What you're seeing is expected behavior; based on any number of influence factors, the order of the rows returned can be different from case to case, from server to server.
This might have to do with the arrangement of the pages that SQL Server reads from disk, or many other factors.
In brief: if you need order, ask for it by ORDER BY
- that's really all there is to know.
精彩评论