How to fetch the next Identity value from Sql Server?

 Posted by vishalneeraj-24503 on 2/3/2015 | Category: Sql Server Interview questions | Views: 215 | Points: 40
Answer:

We have to write below query:-
SELECT IDENT_CURRENT('table_name') + 1

This is correct, but when table is empty and next identity value is set to "1" returned "2" but result is "1"
When the IDENT_CURRENT value is NULL because the table has never contained rows or has been truncated,the IDENT_CURRENT function returns the seed value.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response