Re: Pragmatically changing a "Record Number"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Aug 29, 2007, at 3:02 PM, Richard Lynch wrote:

On Wed, August 29, 2007 12:49 pm, Jason Pruim wrote:
I think after I get this question answered, I can stop asking for
awhile since my project will be done, at least until the users say
"What happened to XYZ????" then I'll ask again :)

I asked on a MySQL list about "Resetting a auto increment filed" so
that there arn't any gaps in the record number.

So to say it another way, I have a table that has 900 records in it,
I've added 3 records, but then deleted 2 of those which puts the
actual record count at 901 but my auto increment field starts at 904
on the next insert.

Is there away with PHP that I can pragmatically change that value to
the total records in the database more so then a representation of
the actual record number?

Can you do this?

Sure.

update whatever set ID_field = 901 where ID_field = 904

Of course, if that 904 is in some OTHER table, then you MUST update
that other table at the same time, in an ACID transation, to be sure
you don't get your relationships all kerflummoxed.

Currently there is only the 1 table and it is going to stay that way...

SHOULD you do this?

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!

The ID key field of a record should not have any explicit meaning.

If you try to re-number your records so it does, it will just cause
you grief and give you nothing useful in return.

If you actualy have a table where there *IS* an ordering of the
records which is meaningful, and it really SHOULD be 1 to N, then add
another field "rank" (or somesuch) and manipulate that independent of
the ID field, which you should never care about its actual number.

Which is what I have figured out from the people on this list, I have decided to not play with the auto increment field, but the need I'm looking for hasn't changed, just the method.

in excel this would be the same as clearing the info in a row and then sorting it to take out the blank lines to get an accurate count of the total records.


To explain WHY this is, would be way bigger than an email that's
already off-topic for PHP, but they should have told you on the MySQL
list.

Or not, as it's probably in their FAQ which you should have read.

If nothing else, the hassle of keeping all those IDs sorted out is a
TON of extra code that serves little purpose, and a single tiny
mistake can make a pig's breakfast of your entire database.  Bad Idea.

No one has but it that plainly to me yet, and they are just suggesting ways to do it more then a don't do it type approach :)


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@xxxxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux