Bèlguesmi Sémah Bèlguesmi Sémah - 3 months ago 19
ASP.NET (C#) Question

Next value of a tables identity specification - SQL Server

How can I get the next value of the identity specification using SQL Server?

Don't say

Select (id+1) from Table1
, because it gives wrong results when deleting rows.

Answer

First of all, whatever you are doing, you are likely doing something wrong, because concurrency.

But you can get the next value of the identity column using

select ident_current('TableName') + ident_incr('TableName')