Safest way to get last record ID from a table

Viewed 155516

In SQL Server 2008 and higher what is the best/safest/most correct way

  1. to retrieve the ID (based on autoincrementing primary key) out of the database table?
  2. to retrieve the value of the last row of some other column (like, SELECT TOP 1 FROM Table ORDER BY DESC)?
8 Answers

SELECT LAST(row_name) FROM table_name

Related