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

[no subject]



James Sumners wrote:
> It would be better to do the INSERT first and then get the number.
> That way you can be sure that it is the correct number. But, "SELECT
> pri_key_num + 1 FROM table ORDER BY pri_key_num DESC LIMIT 1;"
> 

Also, note that this will only work if there are zero deletions from the
table in question.  If you make a deletion in a table, and you don't
re-order the table by pri_key_num, then eventually you will find that
you're performing INSERTs that aren't any longer using the correct row
ids, and you'll have gaps in numbering if you use any other method to
add a number.

Checking the new Row ID after an insert is the only real way to go about it.

	- Mike

- --
Michael B. Trausch                                     fd0man at gmail.com
Web: <a  rel="nofollow" href="http://fd0man.theunixplace.com/";>http://fd0man.theunixplace.com/</a>        Jabber: mtrausch at jabber.com
Phone: +1-(678)-522-7934                  FAX (US Only): 1-866-806-4647
=======================================================================
  Do you have PGP or GPG?  Key at pgp.mit.edu, Please Encrypt E-Mail!


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - <a  rel="nofollow" href="http://enigmail.mozdev.org";>http://enigmail.mozdev.org</a>

iD8DBQFCqDVWPXInbkqM7nwRA8CDAJ0VdF6T7s7ll93/wKScKIqoxiXGdwCeKgeH
/eiTjnrIkApxNRBfTsmRGPI=
=xfuC
-----END PGP SIGNATURE-----


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00405" href="msg00405.html">[ale] Getting the next index of a table in mysql</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00401" href="msg00401.html">[ale] Getting the next index of a table in mysql</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
<li><strong><a name="00402" href="msg00402.html">[ale] Getting the next index of a table in mysql</a></strong>
<ul><li><em>From:</em> james.sumners at gmail.com (James Sumners)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00402.html">[ale] Getting the next index of a table in mysql</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00404.html">[ale] Question: Transparent document sharing over the Internet</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00402.html">[ale] Getting the next index of a table in mysql</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00405.html">[ale] Getting the next index of a table in mysql</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00403"><strong>Date</strong></a></li>
<li><a href="threads.html#00403"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

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