s

sql server get identity value before insert edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 27 November 2020 | 1982

I wanted to know the auto-generated identity value before I do an Insert statement. I have a table named setupcountry and I had set the NumercId column as identity with type integer.

Solution

select IDENT_CURRENT('yourtablename')            

                    

Returns the last identity value generated for a specified table. NULL is returned on error or if you do not have permission to view the object