[RESOLVED] Identity Specification Column in Table Not Displaying In Numerical Order
The title of this thread says it all. I have a database table and the column that has identity specification set to true is not displaying in numerical order. Whether I use Server Explorer and use Show Table Data or I create an application to view the contents of the table using a DataGridView I see that column displayed with the numbers often though not always in a non-numerical order.
Does it perhaps have to do with the way the rows for that column were added or would it be something else. I was looking at the properties for that column but don't see what I would change to make the rows display in numeric order.
Re: Identity Specification Column in Database Table Not Displaying In Numerical Order
The only way to be sure that a database system will return records in a particular order is to explicitly ask for it, using an Order By clause or the equivalent (perhaps via properties of the DataGridView for example), eg:
Code:
SELECT fieldA, fieldB
FROM table1
ORDER BY fieldA Asc, fieldB Desc
If you don't specify an order, the database system can return the records in any order it wants at that particular moment, which can vary from one time to the next for a variety of reasons (including pages that are already stored in memory, multiple user locking, relevant indexes available, etc).
Re: Identity Specification Column in Database Table Not Displaying In Numerical Order
Ok, thanks for the reponse. When I said, "I see that column displayed with the numbers often though not always in a non-numerical order", that wasn't really what I meant. What I should have said is that parts of the column were in numerical order but other parts weren't.
Anyway I deleted a bunch of rows from my table so that there were just three left. I then used my code that was adding rows and everything is now displaying in numerical order. I was using different methods at different times to update my table and that might be part of the problem but now I see all the new rows that I added displaying in numerical order so for the time being I won't worry about the problem I saw before. If I see it come back then I'll start to think about it again.
Re: [RESOLVED] Identity Specification Column in Table Not Displaying In Numerical O
When I marked this resolved I had a feeling I might be seeing this problem again and I did see it again. Taking si's hint I built a query that sorts the column I want in ascending order and now my problem is solved.