How to get IDENTITY number of table IDENT_INCR and IDENT_SEED FUNCTION of IDENTITY column IN sql server

Hi, How to get current identity value of a specific table in sql server? How to get current max identity value of a specific table?
Okay, Follow me.

Syntax:

SELECT 
IDENT_INCR('TableName')

HOW TO GET IDENTITY NUMBER OF TABLE

Come on, let’s make an example.

CREATE TABLE #TEST (
    ID INT IDENTITY(100,30),
    TestName VARCHAR(20)
)
SELECT 
IDENT_INCR('#TEST') AS [INCR],
IDENT_SEED ('#TEST') AS [SEED],
IDENT_CURRENT('#TEST') AS [CURRENT]

HOW TO LISTING ALL IDENTITY NUMBER ON A DATABASE

SELECT IDENT_SEED(TABLE_NAME) AS Seed,
IDENT_INCR(TABLE_NAME) AS Increment,
IDENT_CURRENT(TABLE_NAME) AS Current_Identity,
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'TableHasIdentity') = 1
AND TABLE_TYPE = 'BASE TABLE'
sql current identity for all table

HOW TO GET MAX IDENTITY NUMBER OF TABLE?

Specify your identity column.

SELECT MAX(Id) FROM #TEST

Thank You!

Leave a Reply