To get the next identity value from SQL Server

If you have table with no. of rows and you want to find out next id, following query can be used to identify:

SELECT IDENT_CURRENT(‘<Table Name>’) + IDENT_INCR(‘<Table Name>’)

You cannot reliably find out the next identity value – until you’ve actually inserted a new row into the table.

From the IDENT_CURRENT documentation:

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.

Happy Coding 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s