If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Missing index values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-31-06, 14:48
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Missing index values

Hi there!

my_table has 23043 records.
The next autoindex indicates 23047.
I have verified the largest index value allocated which is 23046 and which is correct.

How can I find the two index values which aren't used?
(so I can use them with new records and therefore have the index values and the number of records having the same value : 23046).

Many thanks in advance for your help.
Reply With Quote
  #2 (permalink)  
Old 12-31-06, 16:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
please consider changing your strategy

the purpose of the auto_increment is to provide uniqueness only

any attempt to compensate for "gaps" in the numbers is wrong and you should try to find another way to do whatever it is you're doing with the numbers
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-31-06, 17:08
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,259
agree with Rudi
autonumber columns / identity columns are system generated.. they have no meaning outside the system itself. if you are trying to force an exteranl meaning onto such a column it will fail.
if you need to have sequential numbers then you need to develop a stratgey to generate the nnext availabel number.. its been covered inthis trhead, and other trheads on this forum ad nauseam.

however to answer your question....
first off are you not bothered about hte third missing number in your set?
you could send a series of sql queries counting the number fo records in each set untill you find the missing gaps

the SQL would be something like select count(<mycolumn>) as NoRecs from <mytable> where <myautonumbercolumn> >x and <myautonumbercolumn> < y
you could do it by writign a bit of quick & dirty code or do it in something like MySQL Query Browser. if you satrted off say with a range of a hundred it woul failry quickly narrow down where the problem is, then make the range say 10's.. equally ytou can size a query window so that the display is in a simple multiple (Id suggest soemthign like displaying 20..40 records.. do a page down untill the last record on the screen is no longer in the sequence you expect. it may be quicker that say writing a bit a of code
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 12-31-06, 18:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
headlem yuo nede a nwe kyeboadr, yuors kepes swtiching lettesr aruond

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-01-07, 00:39
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Nah, the keyboard is Ok, it is just a loose nut attached to the keyboard combined with a need for either a spell checker or a proof reader!

-PatP
Reply With Quote
  #6 (permalink)  
Old 01-04-07, 05:13
Yveau01 Yveau01 is offline
Registered User
 
Join Date: Dec 2005
Location: Tilburg, Netherlands
Posts: 73
This query will cough up the missing values (and the next in line)

Code:
select t.Column + 1
from   Table t
where  not exists
(      select  t2.Column
       from    Table t2
       where   t2.Column = t.Column + 1)
Good luck.

Gr,
Yveau
__________________

> SELECT * FROM users WHERE clue > 0;
Empty set (0.00 sec)

Reply With Quote
  #7 (permalink)  
Old 01-04-07, 06:16
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,259
Quote:
Originally Posted by Pat Phelan
Nah, the keyboard is Ok, it is just a loose nut attached to the keyboard combined with a need for either a spell checker or a proof reader!

-PatP

faircopyerhonner.....

I think that the proble is getting worse.. mebbe Mad Cow Disease is more prevalent than I first thought
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On