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 > problem with AUTO_INCREMENT

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-12, 17:07
ihatebugs ihatebugs is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
problem with AUTO_INCREMENT

hi all

I have created a table with: id | message | date

at first, all seemed to work fine BUT the id (AUTO_INCREMENT) doesn't reset itself back to 1 when i delete all the rows, it continues counting from the last row example

id message
1 xxxxx
2 xxxxx
3 xxxxx

now if i delete where id=3, and then insert a new row, it will look like this:

id message
1 xxxxx
2 xxxxx
4 xxxxx
Reply With Quote
  #2 (permalink)  
Old 01-09-12, 17:24
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
That is the correct, expected behaviour.

Can you explain to us why you'd want it any other way?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 01-09-12, 17:27
ihatebugs ihatebugs is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Quote:
Originally Posted by gvee View Post
That is the correct, expected behaviour.

Can you explain to us why you'd want it any other way?
ah nvm then, i can do this a different way its to do with a program im writing in assembly to work with the db.
Reply With Quote
  #4 (permalink)  
Old 01-09-12, 20:23
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Before you go ahead with your other method can you tell us why you need a perfectly sequential identifier for your records? I don't like to say it but chances are you have a flaw in your design.
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 01-09-12, 20:30
ihatebugs ihatebugs is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Quote:
Originally Posted by gvee View Post
Before you go ahead with your other method can you tell us why you need a perfectly sequential identifier for your records? I don't like to say it but chances are you have a flaw in your design.
I've not worked with SQL for a very long time so i forgot that AUTO_INCREMENT works in the way it does. I was trying to delete a row based on the selected index of a listbox item but of course that would fail sinse the list box index could be 3 and the ID in the sql table could be 4. So instead i'm using listview32 API with a column for the ID, this way i can delete a row using the correct id from the sub column. And now everything is working fine, ready for my client
Reply With Quote
  #6 (permalink)  
Old 01-10-12, 00:19
mathukumali mathukumali is offline
Registered User
 
Join Date: Jul 2010
Location: ISHHHH
Posts: 130
If you want to get sequence after deleting the row u had to insert value directly to the auto increment column
__________________
WiTh Tnks & ReGaRdS
mAtHuKuMaLi
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