6 Different Ways To Get The Current Identity Value

by 3:40 AM 0 comments
CREATE TABLE TestOne (id INT IDENTITY,SomeDate DATETIME)
    CREATE TABLE TestTwo (id INT IDENTITY,TestOneID INT,SomeDate DATETIME)
 

    INSERT TestOne VALUES(GETDATE())
    INSERT TestOne VALUES(GETDATE())
    INSERT TestOne VALUES(GETDATE())
    INSERT TestOne VALUES(GETDATE())



6 ways to check for the current value:

@@IDENTITY

SELECT @@IDENTITY

DBCC CHECKIDENT

DBCC CHECKIDENT (TestOne, NORESEED)

MAX function

SELECT MAX(idFROM TestOne

TOP 1 and ORDER BY DESC

SELECT TOP 1 id FROM TestOne ORDER BY id DESC

IDENT_CURRENT

SELECT IDENT_CURRENT('TestOne')

SCOPE_IDENTITY

SELECT SCOPE_IDENTITY()


ravi tuwar

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 comments:

Post a Comment