Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 auto increment gone wild

Author  Topic 

sqlconfused
Yak Posting Veteran

50 Posts

Posted - 2013-08-22 : 00:28:08
Hi... I'm using a SQL 2008 database on a SQL 2012 hosted server. I have an autoincrement ID for locations that my members create. These go up by 1.... eg. 9400, 9401, 9402.

Tonight a member attempted to make a new location and the ID went from 9407, 9408 and JUMPED to 10408. Any subsequent creations only continue from 10408 onwards.

Any idea what happened here? 9409 to 10407 just aren't available.

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-22 : 01:17:40
May be you are handling exceptional cases... If the INSERT operation failed how you handled that scenario...
CREATE TABLE TestIdent (col1 int identity, col2 CHAR(1))
insert into TestIdent values('A')
insert into TestIdent values('B')
insert into TestIdent values('C')
insert into TestIdent values('AB') -- failed to insert
insert into TestIdent values('D')

SELECT * FROM testIdent
/*
-- Here 4 is missing
col1 col2
1 A
2 B
3 C
5 D
*/
DROP TABLE testIdent



CREATE TABLE TestIdent (col1 int identity, col2 CHAR(1))
DECLARE @input VARCHAR(5) = 'AB' -- success for single character.. If size exceeds 1 then error, at that time you should rollback the operations(transaction)
BEGIN TRY
insert into TestIdent SELECT @input
SELECT * FROM testIdent
END TRY
BEGIN CATCH
SELECT @@ERROR
END CATCH
GO
DROP TABLE testIdent


--
Chandu
Go to Top of Page

erikhaselhofer
Starting Member

30 Posts

Posted - 2013-08-22 : 01:20:16
Someone created / inserted a bunch of records by mistake and deleted them? Someone reseeded the table? Something else?



Go to Top of Page
   

- Advertisement -