Is it bad practice though to assume that the highest numbered autonumber / primary key would be the last record?
If you mean the last inserted record then that is a decent approach - autonumber
will never go "backwards" (but can go negative as mentioned below).
However, there's a few edge cases that you don't specify which may change the right answer:
- what if two records have the same
DateTime
value? Would they both be considered the "last" record?
- Would you ever insert a record with an earlier
DateTime
(say as an import from an external source or merging two datasets.
- Will you have more than 2 Billion records? If so then you rick having the autoincrement integer rolling over to a negative number
EDIT
Based on comments and donwvotes, I'm revising my answer to agree that an autoincrement field is not the best solution to determine the "last" record. There are too many cases where it could be wrong to recommend it.
All in all, if your definition of "last" is "the record with the highest DateTime
value" - then use that!
You can add an index on DateTime
which will speed up queries against that column significantly.