You're touching on something fundamental about the relational model here. In databases on the whole, there's no such thing as an intrinsic ordering. If you want to get an ordering out of data whenever you look at a table, you must specify that order explicitly.
So in a general sense, you're asking for the impossible. You can't just UPDATE
a table and get an automatic ordering out any query you make on it. But in a query-by-query sense, you could always put "ORDER BY item1ID, sortOrder
" in any SELECT
statement you apply to the table.
In SQL Server 2005, you could write a view and present it to your client, using this old hack:
SELECT TOP 100 PERCENT
item1ID, item2ID, sortOrder -- and all the other columns
FROM YourTable
ORDER BY item1ID, sortOrder;
There are ways of making such a view updateable, but you'll need to research that on your own. It's not too hard to do.
If you're never going to insert or change data in this table, and if you're willing to reimport the data into a table again, you could define your table with an identity, then insert your data into the table in the appropriate order. Then you would always order by the one identity column. That would work if your client always views the data in a program that allows sorting by a single column. (BTW, never use the IDENTITY
function for this purpose. It won't work.)
CREATE TABLE YourTable (
SingleSortColumn INT IDENTITY(1,1) NOT NULL,
...
);
INSERT INTO YourTable (
item1ID, item2ID, sortOrder -- everything except the SingleSortColumn
)
SELECT -- all your columns
INTO YourTable
FROM yadda yadda yadda
ORDER BY item1ID, sortOrder;
Hope that's helpful. Sorry if I'm being pedantic.