Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 23rd, 2003, 01:21 PM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
auto_increment

I have database connected to my site (MySQL).
I have table with messages there and first value is idn where I store number that is autoincrementing for each message.

Here is my problem:
when I have messages with number 1, 2, 3 and I delete message with number 3 and then I add new message its number is 4 and there is no message with number 3. Same problem is when I delete messages form middle of my database.

It is not big problem, but I do not like it. Do you have idea how to solve it?

Reply With Quote
  #2  
Old February 23rd, 2003, 07:52 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: auto_increment

Well, you can't AFAIK. The only way to change MySQL's auto_increment counter is to delete everything from the table (as in "DELETE FROM table"), which sets it back to 1.

The only other option you have is to check the IDs manually, but that is slow..

Reply With Quote
  #3  
Old February 24th, 2003, 04:55 PM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
RE: auto_increment

Thanks for answer.

I hoped there will be some hidden why how to "reincrement" this one column time by time by some sql syntax.

Reply With Quote
  #4  
Old February 24th, 2003, 05:13 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: auto_increment

Actually, if you delete the last entry, it can be reused:
ALTER TABLE table AUTO_INCREMENT=1;

If you delete a non-final ID, it will not get picked up, though. It seems the formula is max(id)+1.

Reply With Quote
  #5  
Old February 25th, 2003, 01:03 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: auto_increment

you can also set the value of the auto_inc column when inserting/updating row, but you would have to set to the non-existing one...

Code:
INSERT INTO table SET id=17, name='blah..'


(asuming row with the id of 17 was deleted, or wasn'e created yet...)

Reply With Quote
  #6  
Old February 27th, 2003, 11:32 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
RE: auto_increment

Actually it seems that is could be possible to delete column with idn after deleting non-final news and then add it and autincrement it. However I do not think I will do it, it is not worth work, it is working well without it.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > auto_increment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT