Wednesday, 28 January 2015

Run this Query and Feel Difference between @@IDENTITY SCOPE_IDENTITY() and IDENT_CURRENT

---Run this Query in ur Query window of SQL and feel  the difference! ;)

IF object_id('tempdb..#IndexDetails') IS NOT NULL
                                  DROP TABLE #IndexDetails;
                                  CREATE TABLE #IndexDetails (
                                  Id INT IDENTITY(1, 1)
                                  ,IndexID INT DEFAULT(0))
                                 
IF object_id('tempdb..#IndexDetails2') IS NOT NULL
                                  DROP TABLE #IndexDetails2;
                                  CREATE TABLE #IndexDetails2 (
                                  Id INT IDENTITY(1000, 1)
                                  ,IndexID INT DEFAULT(0))
                                               
INSERT INTO #IndexDetails (IndexID)
VALUES(1001)

INSERT INTO #IndexDetails2 (IndexID)
VALUES(1001)

SELECT @@IDENTITY
SELECT SCOPE_IDENTITY()
SELECT IDENT_CURRENT ('#IndexDetails') AS Current_Identity;


No comments:

Post a Comment