Maybe I'm missing something here but the use of a clustered index can
enforce ordering on a table as the following demonstrates:
CREATE TABLE OrderTest
(
OrderKey int not null,
SomeOtherJunk varchar(50) not null
)
CREATE CLUSTERED INDEX IX_OrderTest_01 ON OrderTest(OrderKey)
INSERT OrderTest
VALUES(100, 'William')
INSERT OrderTest
VALUES(1, 'Phil')
INSERT OrderTest
VALUES(10, 'Rich')
INSERT OrderTest
VALUES(1000, 'Sam')
SELECT * FROM OrderTest
By using the DESC keyword in the CREATE INDEX statement you can reverse the
ordering.
If you are trying to ensure the sort order of a text field (char, varchar
etc) it gets a little trickier - ordering in the clustered index is also
dependant on things like the collation settings. On my install of SQL for
example, if you change the clustered index above so it applies to the
SomeOtherJunk field, it comes out in the general latin case-insensitive,
accent-sensitive ordering; Phil, Rich, Sam, William
(SQL_Latin1_General_CP1_CI_AS). A different collation may give you different
ordering (although in this case probably not).
--
Phil
http://www.clarity-integration.com
http://www.phil-austin.blogspot.com
"bala" wrote in message
>
>
> "ML" wrote:
>
>> Sets are unordered which means there is no inherent order in SQL objects
>> (tables, views). For instance: the order of inserted rows is not
>> preserved,
>> and when retrieving rows from the table (or view) the order is not
>> guaranteed
>> unless the ORDER BY clause is used in the referencing (SELECT) query.
>>
>> If you need to preserve the order of your data then you must design your
>> own
>> method of doing so. The usual practice is either to use an existing
>> column to
>> sort the rowset or add a column (i.e. directly to the source or through
>> staging) to store the original row order.
>>
>> In Excel you could just add a column and fill it with numbers designating
>> the original row order.
>>
>> Do not rely on the IDENTITY column in a SQL table to preserve the order
>> as
>> the optimizer is free to choose the way rows are inserted, which means
>> (as
>> mentioned) before that the order may not be preserved.
>>
>>
>> ML
>>
>> ---
>> Matija Lah, SQL Server MVP
>> http://milambda.blogspot.com/
>
> thank you very much. Your answer is very help full to me. I add one column
> in both xl and in that sql table and give row no to it. Then import the
> data
> from xl. Now the sequence is very correct with my xl file that is the row
> hasn't changed it's order. But I have no permission to add one column in
> my
> sql table. So after imported the data I deleted that column what I have
> added
> extra in sql table then again all rows are changed it's order.
> Actually one customized tool has given for entering data to that sql
> database. If I entered the data through that tool then the row order may
> be
> correct (what order I has entered) or we can't preserve the row order?
> please
> help me. >> Stay informed about: Row of data interchaged automatically when import from MS ..