Hi! I needto find the last record that has been inserted on a table. If I perform a SELCT * FROM mytable , will I receive the data based on the inserted order (natural order)? In that case i'll simply need to check the last record of the results I got in my application to find the last inserted one? (no I am not looking for an identity number ^^)
You can't rely on the order in which the SELECT statement fetch records unless you specify ORDER BY. To determine First or Last record, you have specify column which can be used to specify order (e.g. inserted_date column).
Harsh Athalye India. "The IMPOSSIBLE is often UNTRIED"
"I needto find the last record that has been inserted on a table"
SELECT TOP 1 * FROM mytable ORDER BY SomeColumn DESCENDING
[SomeColumn] needs to reflect the insertion order - e.g. IDENTITY or Date/Time
Relational Databases don't have any inherent order to the data - if another query has just run, selecting part of the data, that will influence the order that SQL Server "sees" the data in the next query.
So you need a column that defines the "insertion order"
thank you for your suggestions - the previous system was based on dBase and there was a kind of natural order that was used to retrieve this value. Of course having an identity date/time insertion is more simple ^_^