473,473 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP / MySQL - auto increment id

I just did my first PHP/MySQL database (a simple survey) that works
fine. It is ordered by an id field that auto increments. Apparently, one
entry repeated (I'm thinking the user hit the submit button twice). So,
I deleted a record. My question is, how do I make it so the next entry
will use the id# that I deleted, so there won't be a gap in the id numbers?
Jul 17 '05 #1
4 9688
On Thu, 02 Sep 2004 23:45:08 GMT, Neal <pi****@comcast.net> wrote:
I just did my first PHP/MySQL database (a simple survey) that works
fine. It is ordered by an id field that auto increments. Apparently, one
entry repeated (I'm thinking the user hit the submit button twice). So,
I deleted a record. My question is, how do I make it so the next entry
will use the id# that I deleted, so there won't be a gap in the id numbers?

Login to SQL (phpMyAdmin for example) and change the auto_increment
value back one.. so if it currently reports 12, make it 11.

In phpMyAdmin, this is under the 'Operations' tab after selecting the
required table.
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #2
"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:7r********************************@4ax.com...
On Thu, 02 Sep 2004 23:45:08 GMT, Neal <pi****@comcast.net> wrote:
I just did my first PHP/MySQL database (a simple survey) that works
fine. It is ordered by an id field that auto increments. Apparently, one
entry repeated (I'm thinking the user hit the submit button twice). So,
I deleted a record. My question is, how do I make it so the next entry
will use the id# that I deleted, so there won't be a gap in the id
numbers?

Login to SQL (phpMyAdmin for example) and change the auto_increment
value back one.. so if it currently reports 12, make it 11.

In phpMyAdmin, this is under the 'Operations' tab after selecting the
required table.
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/


Neal --

While this would certainly fill the ID gap =), it's generally not a good
idea to change an auto_increment ID in a database, in case the ID is used as
a foreign key in another database. Having gaps in ID #'s in a database is
not necessarily a bad thing. More often than not it's inconsequential. Best
to just leave the ID #'s where they are and not change them.

- JP
Jul 17 '05 #3
On Fri, 03 Sep 2004 02:43:13 GMT, "kingofkolt"
<je**********@comcast.net> wrote:
"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:7r********************************@4ax.com.. .
On Thu, 02 Sep 2004 23:45:08 GMT, Neal <pi****@comcast.net> wrote:
>I just did my first PHP/MySQL database (a simple survey) that works
>fine. It is ordered by an id field that auto increments. Apparently, one
>entry repeated (I'm thinking the user hit the submit button twice). So,
>I deleted a record. My question is, how do I make it so the next entry
>will use the id# that I deleted, so there won't be a gap in the id
numbers?


Login to SQL (phpMyAdmin for example) and change the auto_increment
value back one.. so if it currently reports 12, make it 11.

In phpMyAdmin, this is under the 'Operations' tab after selecting the
required table.
HTH =)



Neal --

While this would certainly fill the ID gap =), it's generally not a good
idea to change an auto_increment ID in a database, in case the ID is used as
a foreign key in another database. Having gaps in ID #'s in a database is
not necessarily a bad thing. More often than not it's inconsequential. Best
to just leave the ID #'s where they are and not change them.

- JP

Agreed =)

I rarely change the IDs.. only occasionally within my dev environment.
As you rightly point out, changing these can have disastrous effects in
sometimes, the least expected places if not careful.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #4
On Thu, 02 Sep 2004 23:45:08 GMT, Neal <pi****@comcast.net> wrote:
I just did my first PHP/MySQL database (a simple survey) that works
fine. It is ordered by an id field that auto increments. Apparently, one
entry repeated (I'm thinking the user hit the submit button twice). So,
I deleted a record. My question is, how do I make it so the next entry
will use the id# that I deleted, so there won't be a gap in the id numbers?


Could you explain why you want to do this?

AUTO_INCREMENT gives you a unique identifier that't not been used before. You
shouldn't make any assumptions that the sequence of numbers you get is
gap-free. And besides, the row with that ID has been deleted - why should
another different row get the same identifier?

If you're worried about running out of numbers, consider that an INT UNSIGNED
will last over 136 years at one new record every second - that's 4,294,967,295
rows.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sugapablo | last post by:
Let's say I create a new record in a table like this: mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn); ....that had an auto-incrementing, unique identifying column named "ID"...
19
by: Westcoast Sheri | last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database (2 columns: "fruit" and "quantity")....so can we make these following mySQL queries work somehow? (visitor buys 5...
2
by: shoa | last post by:
Hello I can link MS Access (front) with MySQL (back end). However, when I add a new record, the previous added record is signed as Deleted record (view in Access) even I can view this record in...
1
by: Ward B | last post by:
Greetings. I'm somewhat new to this whole MySQL/PHP thing and need a little help. My web hosting service uses phpMyAdmin and at the bottom of the screen iis an area where I can upload a text...
1
by: Smriti Dev | last post by:
Hi There, I hope you can help with this problem I have been having. I have linked tables from a mysql database and an access database. One of the fields (my primary key field) is an auto...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
13
by: miker2 | last post by:
HI, I'm having trouble writing to a MySql db using python and the MySQLdb module. Here is the code: import MySQLdb base = MySQLdb.connect(host="localhost", user="blah", passwd="blah",...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
0
by: vanisathish | last post by:
Hi, I'm facing a strange intermittent problem. I've my mySQL server running & another process updating a table continuously. One of the field in the table is Auto-Increment. When my PC is...
1
by: cool84 | last post by:
hai, 1. i need help on how to set the auto incremental as "REF0001","REF002","REF003",.......and so on. 2. i declare the field as integer but i want the prefix "REF" follow by the ...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.