Re: [PHP-DB] Auto Increment Problems....
On Mon, 29 Jul 2002 20:44:54 -0700 Georgie Casey "Georgie Casey" <[EMAIL PROTECTED]> wrote: > rite, > > my primary key column ("id") is set to auto_increment as usual > which is very > handy. But when I delete a row, the auto_increment just keeps > incrementing > and there's this 'hole' left where I deleted the row! > > Apart from this looking ugly, it poses another problem. In my PHP > script > where I can add new rows, I query the table, checking how many > rows in the > table altogether and set the new id as the next number, but this > doesnt work > if theres 'holes' in the id field, as the new record tries to > overwrite > another id. > > So I've 2 questions > 1) Can the next auto_increment value be 'set' by a SQL query > 2) Can I get a SQL query to INSERT INTO the first 'hole' it finds > in the ID > column?? > > TIA Why do you want to create your own ID when one is created for you automatically? If you want to know how many rows are in a table, you can use "SELECT COUNT(*) FROM table" (at least using MySQL). If you need the ID of the last row inserted to be able to stick that ID into another table, using PHP, try "mysql_insert_id()". -- Raquel Happiness is not the absence of conflict; it is the ability to cope with it. --Unknown -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Auto Increment Problems....why?
but you said this problem was the holes, what happnes when you fill an auto_incement number in a 'hole' then the next number exists... does it skip the next number(501) because it exists or does it give an error saying duplicate entry for primary key??? It just seems to make sense to me that you'll have holes, it is just a unique identifier, the data is correct, isn't that what is important? i'm not saying this to be a pain, i've struggled with this concept myself and continue to come to the conclusion that i don't care if there are holes, i'd rather have the info in the same order it was inserted into the table and have that row uniquley identified...but i'd like to hear other reasons for doing such a thing. As i don't see how it helps the most important issue...data integrity. my 2cents.if i offended, it was not the point, just trying to learn something new. "Georgie Casey" To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Auto Increment Problems 07/29/2002 11:51 PM why, is this question asked a lot??? anywa, thanks, i was gonna try something like that from something i read in the mysql manual, but it only mentioned it passing and didnt give an example or anything. tanx "Daniel Brunner" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Once again... > > > ALTER TABLE table1 AUTO_INCREMENT = 500 > > > Dan > > > > On Monday, July 29, 2002, at 10:44 PM, [EMAIL PROTECTED] wrote: > > > rite, > > > > my primary key column ("id") is set to auto_increment as usual which is > > very > > handy. But when I delete a row, the auto_increment just keeps > > incrementing > > and there's this 'hole' left where I deleted the row! > > > > Apart from this looking ugly, it poses another problem. In my PHP script > > where I can add new rows, I query the table, checking how many rows in > > the > > table altogether and set the new id as the next number, but this doesnt > > work > > if theres 'holes' in the id field, as the new record tries to overwrite > > another id. > > > > So I've 2 questions > > 1) Can the next auto_increment value be 'set' by a SQL query > > 2) Can I get a SQL query to INSERT INTO the first 'hole' it finds in > > the ID > > column?? > > > > TIA > > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Auto Increment Problems....
Yeah, it's asked a lot!! And I've always answered that question( it's not the only question I answer!!! ) But Good Luck!! And your welcome!!! Dan On Monday, July 29, 2002, at 10:51 PM, [EMAIL PROTECTED] wrote: > why, is this question asked a lot??? anywa, thanks, i was gonna try > something like that from something i read in the mysql manual, but it > only > mentioned it passing and didnt give an example or anything. > > tanx > > "Daniel Brunner" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... >> Once again... >> >> >> ALTER TABLE table1 AUTO_INCREMENT = 500 >> >> >> Dan >> >> >> >> On Monday, July 29, 2002, at 10:44 PM, [EMAIL PROTECTED] wrote: >> >>> rite, >>> >>> my primary key column ("id") is set to auto_increment as usual which >>> is >>> very >>> handy. But when I delete a row, the auto_increment just keeps >>> incrementing >>> and there's this 'hole' left where I deleted the row! >>> >>> Apart from this looking ugly, it poses another problem. In my PHP >>> script >>> where I can add new rows, I query the table, checking how many rows in >>> the >>> table altogether and set the new id as the next number, but this >>> doesnt >>> work >>> if theres 'holes' in the id field, as the new record tries to >>> overwrite >>> another id. >>> >>> So I've 2 questions >>> 1) Can the next auto_increment value be 'set' by a SQL query >>> 2) Can I get a SQL query to INSERT INTO the first 'hole' it finds in >>> the ID >>> column?? >>> >>> TIA >>> >>> >>> >>> -- >>> PHP Database Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Auto Increment Problems....
why, is this question asked a lot??? anywa, thanks, i was gonna try something like that from something i read in the mysql manual, but it only mentioned it passing and didnt give an example or anything. tanx "Daniel Brunner" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Once again... > > > ALTER TABLE table1 AUTO_INCREMENT = 500 > > > Dan > > > > On Monday, July 29, 2002, at 10:44 PM, [EMAIL PROTECTED] wrote: > > > rite, > > > > my primary key column ("id") is set to auto_increment as usual which is > > very > > handy. But when I delete a row, the auto_increment just keeps > > incrementing > > and there's this 'hole' left where I deleted the row! > > > > Apart from this looking ugly, it poses another problem. In my PHP script > > where I can add new rows, I query the table, checking how many rows in > > the > > table altogether and set the new id as the next number, but this doesnt > > work > > if theres 'holes' in the id field, as the new record tries to overwrite > > another id. > > > > So I've 2 questions > > 1) Can the next auto_increment value be 'set' by a SQL query > > 2) Can I get a SQL query to INSERT INTO the first 'hole' it finds in > > the ID > > column?? > > > > TIA > > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Auto Increment Problems....
Once again... ALTER TABLE table1 AUTO_INCREMENT = 500 Dan On Monday, July 29, 2002, at 10:44 PM, [EMAIL PROTECTED] wrote: > rite, > > my primary key column ("id") is set to auto_increment as usual which is > very > handy. But when I delete a row, the auto_increment just keeps > incrementing > and there's this 'hole' left where I deleted the row! > > Apart from this looking ugly, it poses another problem. In my PHP script > where I can add new rows, I query the table, checking how many rows in > the > table altogether and set the new id as the next number, but this doesnt > work > if theres 'holes' in the id field, as the new record tries to overwrite > another id. > > So I've 2 questions > 1) Can the next auto_increment value be 'set' by a SQL query > 2) Can I get a SQL query to INSERT INTO the first 'hole' it finds in > the ID > column?? > > TIA > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Auto Increment Problems....
rite, my primary key column ("id") is set to auto_increment as usual which is very handy. But when I delete a row, the auto_increment just keeps incrementing and there's this 'hole' left where I deleted the row! Apart from this looking ugly, it poses another problem. In my PHP script where I can add new rows, I query the table, checking how many rows in the table altogether and set the new id as the next number, but this doesnt work if theres 'holes' in the id field, as the new record tries to overwrite another id. So I've 2 questions 1) Can the next auto_increment value be 'set' by a SQL query 2) Can I get a SQL query to INSERT INTO the first 'hole' it finds in the ID column?? TIA -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php