Home > SQL Server, T-SQL > IDENT_INCR – SQL Identity – SQL Server

IDENT_INCR – SQL Identity – SQL Server


IDENT_INCR() : this function returns the current identity increment value of an identity column in a table. We need to pass the table name in the function argument to get the value. But, if user does not have permission to view that object then it will return NULL value.

It returns a numeric value as a function output. The range of the numeric data type is numeric(38,0).

Function Syntax

IDENT_INCR ( ‘table_or_view’ )

The function argument should be enclosed by a single quote and the data type must be varying or constant char or nchar.

Example

1. I am creating a table with an identity column with  increment value 2 and insert few rows into the table.

–Creating a table with identity column
create table tblMyWishList
(
ListID int identity(1,2),
WishName varchar(50)
)
GO

–Inserting 5 rows in to the table
insert into tblMyWishList (WishName) values(‘SQLServerRider.com’)
GO 5

SQL Query

pic12. Executing the function IDENT_INCR() to get the increment value

SQL Query

–IDENT_INCR() to get increment value.
select IDENT_INCR(‘[dbo].[tblMyWishList]’) as ‘Incement value’
GO

pic2

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: