I am creating a winform application in c#.and using sql database.
I have one table, employee_master
, which has columns like Id, name, address
try this:
SELECT IDENT_CURRENT('tbl_name') + IDENT_INCR('tbl_name');
To get the next auto-increment value from SQLServer :
This will fetch the present auto-increment value.
SELECT IDENT_CURRENT('table_name');
Next auto-increment value.
SELECT IDENT_CURRENT('table_name')+1;
------> This will work even if you add a row and then delete it because IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.
For MS SQL 2005 and greater:
Select Cast(IsNULL(last_value,seed_value) As Int) + Cast(increment_value As Int) As NextID
From sys.identity_columns
WHERE NAME = <Table_Name>
As for me, the best answer is:
dbcc checkident(table_name)
You will see two values (probably same) current identity value , current column value