We're running SQL server 2012 SP1 x64 (11.0.3000.0)
I have the following table with the InvoiceId
field as the auto-incrementing, primary key:
CREATE TABLE Orders(
InvoiceId bigint IDENTITY(1001,1) NOT FOR REPLICATION,
OrderId varchar(8) NOT NULL,
... -- other fields removed for brevity
CONSTRAINT [PK_ORDERS] PRIMARY KEY CLUSTERED (InvoiceId)
ON [PRIMARY],
)
New rows are inserted though a simple stored procedure like the following:
SET XACT_ABORT ON
SET NOCOUNT ON
BEGIN TRANSACTION
INSERT INTO Orders(
OrderId,
... -- other fields removed for brevity
)
VALUES (
@orderId,
...
)
SELECT @newRowId = SCOPE_IDENTITY()
COMMIT TRANSACTION
The above sproc returns the newly created row-id (Orders.InvoiceId
) to the caller.
The code was working perfectly, with [InvoiceId]
starting from 1001 and incrementing by 1 for each successive inserts.
Our users inserted about 130 rows. [InvoiceId]
was at 1130, then on the next insert its value jumped to 11091!
Here's the data screenshot:
I'm baffled as to what just happened here. Why did the auto-inc counter suddenly skip nearly 10,000 points?
We're using the value of [InvoiceId]
to generate barcodes, so we'd prefer the value to remain in a specific range, preferably in a contiguous series.
I've perused the T-SQL documentation but failed to find anything related to my issue. Is this the normal behavior (arbitrary population) of an identity field?