For autoincrement fields: MAX(ID) vs TOP 1 ID ORDER BY ID DESC

后端 未结 7 1247
甜味超标
甜味超标 2020-12-06 10:20

I want to find the highest AutoIncremented value from a field. (its not being fetched after an insert where I can use @@SCOPE_IDENTITY etc) Which of these two q

7条回答
  •  醉梦人生
    2020-12-06 10:46

    Just compare execution plans and you'll see (press Ctrl+M in Management Studio when editing a query). My wild guess will be that these queries are equally performant provided there is a (clustered) index on Id column.

    However, this as a whole is a very bad idea.

提交回复
热议问题