The physical order of records written to an SQL table are determined by the clustered index if one is present. If one isn't present then they are just added in the order they are inserted and likewise they are returned in the order they are selected unless you use an order by clause.
You should add a "CreateDate" column or an auto incrementing record id column to determine which record is the last record. By default an autoinc primary key column creates the clustered index unless you specify to override it.
IE default value and clustered:
CREATE TABLE Test
(
RecordId INT identity(1000, 1) PRIMARY KEY
)
A nonclustered version:
CREATE TABLE Test
(
RecordId INT identity(1000, 1) PRIMARY KEY NONCLUSTERED
)
[edit]
Also if someone changes a clustered index that you are relying on to determine order than you cannot figure out by a column value then you run the risk of ruining your database by changing an index. This is a bad idea.... add another way to determine record sequence.
[/edit]
Last edited by sknake; Nov 7th, 2009 at 11:11 pm.
Reputation Points: 1749
Solved Threads: 735
Senior Poster
Offline 3,948 posts
since Feb 2009