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
MAX
Select MAX(StudentID) from tbl_Student
From the above two queries, which are better to choose.
MAX and IDENT_CURRENT , according to the technique, will behave the same and both will be equally unreliable.
, , - / , SCOPE_IDENTITY. , , , .:)
, OUTPUT, ID / .
, IDENT_CURRENT, .
IDENT_CURRENT
. IDENT_CURRENT . - , IDENT_CURRENT , MAX .
EDIT:
IDENT_CURRENT MAX, . IDENT_CURRENT, , , @@IDENTITY SCOPE_IDENTITY. IDENT_CURRENT, @@IDENTITY SCOPE_IDENTITY.
@@IDENTITY
SCOPE_IDENTITY