Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2004, 11:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Identity Insert Problems

We are migrating from Sybase to SQL2k. All objects and data have been moved. I'm seeing problems where Identity values are incorrect.

For example the next identity value for my problem table, should be: 468729 but when I run the SP - the Identity column returned is: 425976

That identity was used long ago and other tables are lined up with those keys already.

I suspect when I migrated the tables, somehow my identity columns got seeded wrong and are incrementing at the wrong points. Any suggestions how can I fix my identity column counter?

I have ran DBCC DBREINDEX and UPDATE STATISTICS on this particular table.

_________________________
Joe Horton
Database Developer / Software Engineer
WISHA/Legal Services Software Development
Department of Labor and Industries
Voice (360) 902-5928 fax (360) 902-6200
__________________
_________________________
Joe Horton
Database Developer / Software Engineer
WISHA/Legal Services Software Development
Department of Labor and Industries
Voice (360) 902-5928 fax (360) 902-6200
 
Old April 13th, 2004, 11:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

how are you moving the tables?

if you are using the DTS make sure that in the transformation you are allowing identity insert.


 
Old April 13th, 2004, 12:03 PM
Authorized User
 
Join Date: Jun 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have solved the problem. I was aware that @@Identity would return the last record updated in a SP - but there seems to be a difference between Sybase and M$.

If you have triggers on a table and do an insert - then immediatly capture the @@identitiy - it returns the id from the original insert - not the triggers - whereas M$ returns the id from the last trigger.

Using Scope_identity() instead of @@Identity solved the problem. The reason I was thinking it was a pointer problem was the id being returned in the trigger was nearly the same id I was expecting from the original insert - thereby suggesting to me that new identity's seemed to be returning values already used.

_________________________
Joe Horton
Database Developer / Software Engineer
WISHA/Legal Services Software Development
Department of Labor and Industries
Voice (360) 902-5928 fax (360) 902-6200





Similar Threads
Thread Thread Starter Forum Replies Last Post
problems to insert and into an empty table JeyZ SQL Server 2005 2 September 28th, 2007 01:36 AM
RETURN IDENTITY AFTER INSERT INTO SECOND TABLE pallone SQL Language 2 August 19th, 2006 05:51 PM
Problems with my Insert Statement brendan82 Access 1 January 6th, 2004 08:30 AM
Problems with my Insert Statement brendan82 Beginning VB 6 1 January 6th, 2004 08:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.