SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 auto increment gone wild
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlconfused
Starting Member

Canada
47 Posts

Posted - 08/22/2013 :  00:28:08  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 08/22/2013 :  01:17:40  Show Profile  Reply with Quote
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 - 08/22/2013 :  01:20:16  Show Profile  Reply with Quote
Someone created / inserted a bunch of records by mistake and deleted them? Someone reseeded the table? Something else?



Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000