Best way to get last inserted record in sql server

Hi everyone, I have an Identity column and a Computed primary key column in my table. I need to get the last inserted record right after inserting the record into the database. So I wrote the following queries, can someone say the best choice

SELECT
t.[StudentID]
FROM
[tbl_Student] t
WHERE
t.ID = IDENT_CURRENT('tbl_Student')

Another uses MAXas follows

Select 
MAX(StudentID) 
from tbl_Student

From the above two queries, which are better to choose.

+3
source share
2 answers

MAX and IDENT_CURRENT , according to the technique, will behave the same and both will be equally unreliable.

IDENT_CURRENT , . IDENT_CURRENT , . . IDENT_CURRENT (Transact-SQL). "

, , - / , SCOPE_IDENTITY. , , , .:)

, OUTPUT, ID / .

+4

, IDENT_CURRENT, .

. IDENT_CURRENT . - , IDENT_CURRENT , MAX .

EDIT:

IDENT_CURRENT MAX, . IDENT_CURRENT, , , @@IDENTITY SCOPE_IDENTITY. IDENT_CURRENT, @@IDENTITY SCOPE_IDENTITY.

+2

All Articles