Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

SCOPE_IDENTITY() sometimes returns incorrect value

Mar 6 2012 12:00AM by Guenter   

When using INSERTs on large tables (> 1 millon rows), the SCOPE_IDENTITY() or @@identity functions sometimes return wrong results.

(This was NOT supposed to be fixed in SQL Server versions older than 2012!)

Update: It seems the problem has been fixed in SQL2008 R2 SP1 CU5 (see http://support.microsoft.com/kb/2019779). I have not checked it yet, as in my company CU's are not widely used (because of internal complexity caused by it). Thanks to Johan Bijnens pointing that out.

Read More..   [70 clicks]

Published under: SQL Server Tips ·  ·  ·  · 


Guenter
28 · 6% · 1887
13
 
0
Knew
 
 
0
Incorrect
 
0
Interesting
 



Submit

5  Comments  

  • This really worries me! Why do you think 'sometimes' it works and 'sometimes' it doesn't.

    Do you insert just ONE row immediately followed by set @i=@@identity?

    How do you access the database when this happens? Can you reproduce it in Management Studio. Or is it happening via something like JDBC or .NET?

    commented on Mar 6 2012 3:29AM
    dishdy
    16 · 10% · 3269
  • Apparently Cumulative Update 5 for SQL Server 2008 R2 SP1 has a fix for this bug ... It's been known for ages @@identity should be avoided and scope_identity() is more stable.

    ref: http://sqlblog.com/blogs/aaron_bertrand/archive/2012/02/23/two-new-cumulative-updates-for-sql-server-2008-r2-are-available.aspx

    Worth the test.

    commented on Mar 6 2012 5:01AM
    Johan Bijnens
    1537 · 0% · 13
  • Here are two causes of incorrect scope_identity() values as reported at Microsoft Connect. As far as I can tell, If you avoid these you should be okay:

    @Johan - it's not an issue of @@identity vs. scope_identity(). Both can give the wrong value.

    commented on Mar 6 2012 11:23AM
    ErikEckhardt
    65 · 3% · 898
  • I have used ident_current function and it did not gave wrong value any time.

    commented on Mar 9 2012 11:47PM
    kr.roopesh
    781 · 0% · 39
  • Till now i dont get any issues with ident_current, possibly i need got more experience...grt guys...

    commented on Mar 13 2012 4:03PM
    Robert Dennyson
    11 · 14% · 4420

Your Comment


Sign Up or Login to post a comment.

"SCOPE_IDENTITY() sometimes returns incorrect value" rated 5 out of 5 by 13 readers
SCOPE_IDENTITY() sometimes returns incorrect value , 5.0 out of 5 based on 13 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]