Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 07-13-2007, 04:45 AM   #1
Member (8 bit)
 
Join Date: Apr 2004
Location: Phoenix
Posts: 223
reset autoincrement counter

In MySQL I set up a table with 5 columns (the number doesn't matter so much), the first one I have set to autoincrement. I have tested the table with INSERT and DELETE queries and have been successful with the tests. I've noticed, however, as the rest of you probably know, that even though I've deleted rows, the first column continues counting, even if the previous row was deleted.

i.e.:

1 row2 row3 row4 row5
3 row2 row3 row4 row5
4 row2 row3 row4 row5
6 row2 row3 row4 row5


How do I reset the counting, if possible?
__________________
"Advancement is answering the questions, discovery is questioning the answers."
dataDude is offline   Reply With Quote
Old 07-19-2007, 02:44 PM   #2
Security Dude
Staff
 
kstatefan40's Avatar
 
Join Date: Jun 2003
Location: Derby, Kansas
Posts: 999
Send a message via AIM to kstatefan40 Send a message via MSN to kstatefan40 Send a message via Yahoo to kstatefan40 Send a message via Skype™ to kstatefan40
The pure SQL statement:

PHP Code:
ALTER TABLE tbl_name AUTO_INCREMENT 
1
__________________

Tyler A. Thompson
Small Business Networking Services Specialist
tyler@derbydigital.com
kstatefan40 is offline   Reply With Quote
Old 07-19-2007, 11:21 PM   #3
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
Make sure there are no rows you do this, or if you do, change the 1 to one more than the highest row numbered.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
Force Flow is offline   Reply With Quote
Old 07-20-2007, 06:35 AM   #4
Member (8 bit)
 
Join Date: Apr 2004
Location: Phoenix
Posts: 223
For now I found a way to solve it is to delete the column that autoincrements and then readd it and have it autoincrement. If anybody has a simpler way to solve it feel free to share.
dataDude is offline   Reply With Quote
Old 07-20-2007, 07:26 AM   #5
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Quote:
Originally Posted by dataDude
For now I found a way to solve it is to delete the column that autoincrements and then readd it and have it autoincrement. If anybody has a simpler way to solve it feel free to share.
If the table is empty it is pretty easy to do using either method. I think that I have even just forced a value in the auto-incremented field and that reset it. It the table isn't empty and/or the auto-incremented field is used as a foreign key in another table, you certainly don't want to do this.
__________________

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row
mairving is offline   Reply With Quote
Old 07-21-2007, 01:50 AM   #6
Member (8 bit)
 
Join Date: Apr 2004
Location: Phoenix
Posts: 223
I did it before and it seemed to work. What's wrong with doing it that way? And no, the table is not empty, but I will make a note of the previous suggestion.
dataDude is offline   Reply With Quote
Old 08-04-2007, 09:35 PM   #7
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Why do you need to do this? Like Mairving said, it is generally not a good idea as only problems can occur.
faulkner132 is offline   Reply With Quote
Old 08-06-2007, 10:05 PM   #8
Member (8 bit)
 
Join Date: Apr 2004
Location: Phoenix
Posts: 223
When I tested it I didn't see any issues that happened. I would imagine similar procedures would be done for those online companies using databases for various features and later have to add columns for additional features that would affect every member of such sites. Correct me if I'm wrong about that.
dataDude is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
password reset prevention peekaboo Networking & Online Security 2 03-22-2006 11:28 PM
Need a simple counter Byte 2.0 Web Design / Development 4 08-07-2005 01:19 PM
Telindus Router wont Reset. help! tomert Networking & Online Security 2 03-28-2005 11:12 PM
reset switch ROYP123 Computer Hardware 6 11-01-2004 10:49 PM
Motherboard has power and reset buttons onboard, but.... AlwaysUp Computer Hardware 0 10-25-2003 05:08 AM


All times are GMT -5. The time now is 07:30 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2