If you want to get technical, you're advice is bad as well, as scope_identity will:
"SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function."
No, it is not wrong in this case. Based on the original post it seems apparent that the OP wants the identity of the inserted record and not an identity from a trigger that may be defined on the table that was never mentioned. If you insert a record to a user table and a trigger inserts a record in an "audit" table for logging then SCOPE_IDENTITY() will return the user id, and @@IDENTITY will return the audit log id (if the tables are both set with identities and the user table has a trigger).
>> Thus it may not return the proper id that the user entered right?
Yes, it will. They did not enter an ID in this case as I didn't not see the OP indicating about enabling IDENTITY INSERT on the table.
>>my solution was just a quick fix for a small database and someone new, it will work in most instances but the proper method would technically be: SELECT IDENT_CURRENT(’tablename’)
That is the exact same problem as
Select Max(id) from Table and is still a race condition. This is far more likely to be an issue than the parallelism condition of
SCOPE_IDENTITY()
>> Also of note, there is a possible bug when run in parallel with scope_identity as well that get more complicated
I was not aware of this bug. However this bug occurs sometimes where parallel execution plans are generated by the SQL Server which does not happen with
Insert Into Table () Values () , and if it does I have failed to see anything from Microsoft that indicates this. That being said I doubt that bug affects this situation.
I do appreciate you posting that bug though. I myself have queries which are affected by that condition so I'll be sending out a company wide email