MSSQL 2008 - Moving rows up or down without 'ORDER BY' code?

When I do a simple SELECT * FROM Mytable, it list the values in the order they were inserted, however, is there anyway to physically make a change to that order so that every time I do a select * from Mytable the changed order appears?

The reason why I need it this way is because I'm planning in inserting a 'move up' and 'move down' arrow in my grid software, and I thought this would be best instead of using ini files and complex coding.
John86aAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itsdivyaksCommented:
Another way to change the order of items in the select statement is to create a clustered index on the column you want the default select statement with out using the order by clause
0
John86aAuthor Commented:
Can you illustrate with an example please?
0
itsdivyaksCommented:
I created a table with p (col1,col2,col3)
col3 - IDENTITY
and inserted some rows and using select * from p and it gave the following:
col1 col2 col3
7      2      1
7      2      2
7      2      3
1      2      4
2      2      5

Then I created index


/****** Object:  Index [test]    Script Date: 04/08/2011 16:31:03 ******/
CREATE CLUSTERED INDEX [test] ON [dbo].[p]
(
      [col1] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO


After that, I run the query select * from p and then i get the following records:
col1 col2 col3
1      2      4
2      2      5
7      2      1
7      2      2
7      2      3
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

SharathData EngineerCommented:
The records in a table are unorderd set. There is no ordering between the records until you mention the order in your query. Creating clustered index will consume some memory. Create the clustered index if you have other reason also. I dont think creating a clustered index is good idea for just sort purpose. For that matter, you have ORDER BY clause.
0
John86aAuthor Commented:
That's almost what I need, but it'll do.
Thank you!
0
Anthony PerkinsCommented:
If you are under the false illusion that SQL Server will always sort your results without using an ORDER BY clause then you had better think again: SQL Server does not guarantee any order unless an ORDER BY clause is used.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.