Click here to Skip to main content
Click here to Skip to main content

Tagged as

6 Different Ways To Get The Current Identity Value in SQL

, 5 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Identity Value
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())

@@IDENTITY
SELECT @@IDENTITY
DBCC CHECKIDENT
DBCC CHECKIDENT (TestOne, NORESEED)
MAX FUNCTION
SELECT MAX(id) FROM 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()

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ravi Tuvar
Technical Lead IntelliMedia Networks, Inc
India India
No Biography provided
Follow on   Twitter   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 5 Nov 2011
Article Copyright 2011 by Ravi Tuvar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid