I'm working on a project that has hit a bit of a snag: I'm replacing some replication with a home built system so that if replication goes down we don't blow our SLAs with our customers and shell out hundreds of thousands of dollars.
In my research, I learned that inserting records alongside identity values can cause the next identity for the table to be reset, which is something I want to avoid due to key range management issues.
It then seems like the obvious solution would be something like this:
DECLARE @Identity VARCHAR(15), @SQL VARCHAR(MAX)
SELECT @Identity = IDENT_CURRENT( 'dbo.My_Table' )
SET IDENTITY_INSERT dbo.My_Table ON
-- Do my inserts here
SET @SQL = 'DBCC CHECKIDENT ( ''dbo.My_Table'', RESEED,' + @Identity + ')'
EXEC (@SQL)
Would I be killing myself with locking if this happens on a highly used table? Alternatively, has anyone figured out a way to insert identities like replication does without causing the identity value to get reset?
SET IDENTITY_INSERT dbo.MyTable ON;