February 17, 2010

Determine the Next Identity number of a SQL Server Table




A user recently asked me a simple way to calculate the next identity number of a SQL Server 2005/2008 Table. With the SQL Server functions like IDENT_CURRENT and IDENT_INCR, this requirement becomes simple to achieve. We will take the example of the Orders table in the Northwind database to demonstrate the use of these functions. Here’s how:

USE Northwind
SELECT IDENT_CURRENT('Orders') as CurrentIdentity,
IDENT_INCR('Orders') as Increment,
IDENT_CURRENT('Orders') + IDENT_INCR('Orders') as NextIndentity

OUTPUT

NextIdentitySQLServer


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

 
  Feedback:

comments

0 Responses to "Determine the Next Identity number of a SQL Server Table"
 

Copyright © 2009-2014 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions