If I understand correctly, the gist of what you are asking is "how can I find which records are missing from a given sequence?"

If this is true, one method to find out is to use an auxiliary table containing all the sequence numbers, and perform a LEFT JOIN to your table.

First, create such table and fill it with the values from 1 to the maximum record number you want to consider. What Corion said about maximum record number and unique numbers in Transaction are still valid and you should check them. However, assuming that TransactionID is unique, this method will find the missing rows very fast.

#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect("dbi:driver:database", "user","password",{RaiseError=>1}) or die; $dbh->do(qq{ create table sequence (id int not null primary key)) }); my $sth = $dbh->prepare(qq{ insert into sequence values (?) }); $dbh->{autocommit} =0; $dbh->begin; for ( 1.. 1_200_000) { $sth->execute($_); if (($_ % 1000) == 0) { $dbh->commit; $dbh->begin; } } $dbh->commit; my $min = 968000; my $max = 1029829; my $sequence_query = qq{ SELECT a.id FROM sequence a LEFT JOIN Transaction b ON (a.id=b.TranstactionID) WHERE a.id BETWEEN $min AND $max AND b.TranstactionID IS NULL }; $sth = $dbh->prepare($sequence_query); $sth->execute(); while (my ($row) = $sth->fetchrow_array) { print "$row is missing \n"; } $dbh->disconnect();

HTH

 _  _ _  _  
(_|| | |(_|><
 _|   

In reply to Finding missing sequence records in DB table by gmax
in thread DBD::ODBC won't read past a certain record by Groll

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.