Re: Question: Correcting MySQL's ID colomn when removing an entry

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

 



At 12:07 PM +0430 9/20/09, Parham Doustdar wrote:
Hello there,
I'm guessing that when a row in a MySQL table is removed, the ID colomns of the rows which come after that row are not changed. For example:
1
2
3
4

Now, if I want to remove the third rows, the ID colomn would be something like:
1
2
4

I was wondering if there was a way to fix it through a query, so I wouldn't have to use a for statement in PHP to fix it?

Thanks!

Parham:

This is a common problem with people who are new to databases. The sequence of the index of tables has nothing to do with anything important -- there is no reason to be fearful of, or concerned with, gaps. Gaps are normal and a customary part of the database operation.

I often hear managers/clients say "How do we correct that gap?" -- the simple answer is "We don't" and there is no reason to look upon a gap in a sequence as if it needs correcting.

Now, if you want to display a sequence of records (like a product listing), there is no problem with you reading all the products in your database, sorting them, and listing them in numerical order -- however, that listing has nothing to do with the index of the table.

Similarly, you may even want to list your products in alphabetical order and you can do that too, but again that listing has nothing to do with the index of the table.

So in the end, the index in a table has nothing to do with how you store or list your data -- it simply is an internal thing that the database needs to keep track of unique records.

My advice, allow the database to use the index as it needs and you use the data as you need.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
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