Quantcast
Channel: Find all missing records
Viewing all articles
Browse latest Browse all 10

Find all missing records

$
0
0

There is no 100% accurate way to do what you want if you are not currently using triggers or some other method (like switching a flag to "deleted" in the row for a given record).

Identity values are not guaranteed to be without gaps.  For the most part, and in your environment, they may well be, but consider the following scenario:

The current max value in the identity column is 100.

Client 1:
BEGIN TRAN
INSERT INTO TABLE VALUES ('This is a test.') -- Grabs the next identity value of 101

Client 2:
BEGIN TRAN
INSERT INTO TABLE VALUES ('This is another test.') -- Grabs the next identity value of 102
COMMIT TRAN

Client 1:
ROLLBACK TRAN -- simulate an insert error causing the identity value of 101 to not be inserted and perhaps viewed as a "delete" under your model.

In other words, in the above scenario, there will be a gap created in the identity sequence.


Phil Brammer | http://www.ssistalk.com | Twitter: http://twitter.com/PhilBrammer

Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>