SELECT SCOPE_IDENTITY is always resulting id=1, what i hav开发者_如何转开发e done wrong? how to get the currentid of the inserted element.
A good article on the different methods to retrieve the last inserted.
SCOPE_IDENTITY does indeed return the identity column of the last inserted row in the scope you are in.
It can be messed up by a few things, within the same scope. In that case IDENT_CURRENT('myTable')
will be better.
If not you'll want to post more code. SCOPE_IDENTITY does work as you think, so the problem is likely elsewhere.
Are you doing it within the same trasaction? Is the identity actually being incremented in the Database?
Is the column set as Is Identity=Yes?
精彩评论