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

[no subject]



If your index isn't related to anything else (although I can't think why
you would do that, unless this is an unimportant table that is related
to another "primary" table in the database), you can do what you're
asking by something similar to the following:

$query = "ALTER TABLE table_name "
       . "DROP col_name, "
       . "ADD col_name INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, "
       . "AUTO_INCREMENT = 1";
$res = @mysql_query($query, $conn);
if (!$res) { // handle errors }

Just dropping the column, and recreating it (after ensuring that your
table is in order by doing "ALTER TABLE table_name ORDER BY col_name")
will create the appropriate auto-increment field values that you need.

If this is a table that has it's ID field created with relationships to
other tables (enforced by the DB Server or not), be advised that this
may horribly break any applications that are making use of the database.
 The applications can't see what happened or why the relationships are
broken; and in fact, may not even know that the relationships are broken!

	- Mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 294 bytes
Desc: OpenPGP digital signature



</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00298" href="msg00298.html">[ale] Auto increment in MySQL</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00303" href="msg00303.html">[ale] Auto increment in MySQL</a></strong>
<ul><li><em>From:</em> kafka at antichri.st (George Carless)</li></ul></li>
<li><strong><a name="00306" href="msg00306.html">[ale] Auto increment in MySQL</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00338" href="msg00338.html">[ale] Auto increment in MySQL</a></strong>
<ul><li><em>From:</em> groups at changinglinks.com (ChangingLINKS.com)</li></ul></li>
<li><strong><a name="00344" href="msg00344.html">[ale] Auto increment in MySQL</a></strong>
<ul><li><em>From:</em> kafka at antichri.st (George Carless)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00394.html">[ale] BellSouth DSL setup</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00396.html">[ale] Sync a Palm Tungsten T5 with Linux</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00344.html">[ale] Auto increment in MySQL</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00304.html">[ale] Help with UnixWare 7.1.1 networking</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00395"><strong>Date</strong></a></li>
<li><a href="threads.html#00395"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>