Visite Webhosting Latino, el site sobre alojamiento web.
Lost or Missing Records?? - Mombu the Microsoft Forum
Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > Lost or Missing Records??
User Name
REGISTER NOW! Mark Forums Read

sponsored links

1 14th August 22:26
angelique manley
External User
Posts: 1
Default Lost or Missing Records??

Our database is a SQL Server 2000 (sp3). We are
populating the database from transactions on the web which
run through an IPSEC tunnel.

Over the course of several days our counter column on one
of our tables has gaps in the numbering. The gaps stopped
for a few days and then one day started again. This is
all while having a relatively similar volume of traffic.

The table and the counter column are super straight
forward. The table simply receives insert statements. We
aren't duplicating or replicating anything.

The column is the primary key, identity = Yes, identity
increment = 1.

My questions are:

1) How does a new row's counter get incremented in a
situation like this? Could it be that we aren't really
missing records, that the row simply incremented wrong?

2) What might be the possible reason for the counter
number to have gaps occurring?

Any insight would be greatly appreciated.

  Reply With Quote

  sponsored links

2 14th August 22:26
vishal parkar
External User
Posts: 1
Default Lost or Missing Records??

hi Angelique,
There are chances that you will find gaps in the identity columns.

One of the possibility is, that after executing INSERT statement transaction
is getting rolled back.once transaction is rolled back the whenever next
insert statement will successfully completed it will generate the new
identity value and earlier identity value will be missing in the sequence.


create table t(col1 int identity(1,1))
insert into t default values
begin transaction
insert into t default values
rollback --transaction rolled back hence identity value 2 is missing
insert into t default values
select * from t

Vishal Parkar |
  Reply With Quote
3 17th August 19:03
External User
Posts: 1
Default Lost or Missing Records??

One thing that we have to remember for web based databases - not everytime
does a transaction complete itself. What I mean by that is that there could
be instances wherein the transaction tried to complete itself but got
rolled back because of timeouts, some errors etc.

When a transaction gets rolled back, you will find that those increments of
your identity column will never be used again. Hence, the next time the
transaction takes place, the increment value will begin from a latter
number. And hence those gaps.

You can test it yourself on a database in your machine. Try to insert some
records with the following requisites:

[your code to insert some records into a table with identity column set]

Once you do this, try to insert records once again without the transaction
rollback option as mentioned above. You should see those gaps again.

Hope that helps.
This posting is provided "AS IS" with no warranties, and confers no rights.
  Reply With Quote

Thread Tools
Display Modes

Copyright 2006 - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -