MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL 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 Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2000, 05:39 AM
The_Net_Muppet The_Net_Muppet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: England
Posts: 433 The_Net_Muppet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 Days 6 h 9 m 24 sec
Reputation Power: 9
Hello,

I am new to sql so you will have to forgive my questions. I have used MS ACCESS quite allot. When I create 3 records and delete 1 record then add another one the numbering goes out of place.

example:

I create 3 records with the id 1,2,3 I delete record 3, then in the future add another record, it then goes 1,2,4.

Is there anyway in MYSQL to make the numbering go in sequence, if I delete records?.

Thank you for your time.

------------------

Reply With Quote
  #2  
Old July 11th, 2000, 05:47 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
I assume you are talking about auto_increment? If so, what you describe shouldn't happen. If you delete the record with the highest value then the next record inserted should have that value. However, if you delete other than the highest value it won't be replaced. You could reorder with:

delete from table_name where id=$id;
update table_name set id=id-1 where id>$id;

However, that is a bad idea usually. If you have dependencies in other tables based on that id you will create anomolies.

Reply With Quote
  #3  
Old July 11th, 2000, 06:05 AM
The_Net_Muppet The_Net_Muppet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: England
Posts: 433 The_Net_Muppet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 Days 6 h 9 m 24 sec
Reputation Power: 9
>However, that is a bad idea usually. If you >have dependencies in other tables based on >that id you will create anomolies.

Thats true I never thought of that!, thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > record numbering sequence problem


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 5 hosted by Hostway
Stay green...Green IT