Msyql Efficiency Help

windows

Guest
ok...this is is just an example of what I need...don't ask why i would need such a thing b/c its for some script i'm writing for fun...<br />a very simple mysql table...<br /><b>TABLE urls</b><br />->FIELD1 <u>INT</u> "id" this is set to <b>primary and autoincrement</b><br />->FIELD2 <u>VARCHAR</u> "urls"<br /><br />what would be the most <b>efficient</b> way to find the next (id) integer in line to be pushed onto the database. Is there an easy way around this w/o doing a major query to the database. Trying to find the next Cardinality of that key. <br /><br />Remember: the ID is set to autoincrement so it would just be a query to find the max id on that table and just increment.. <br /><br />thanks,<br />Dave<!--content-->
I'm not sure I understand your question correctly because, if you enter a value for FIELD2 and leave FIELD1 as NULL or zero, MySQL will handle the auto-increment for you when you post.<br /><br />If you want to handle the auto increment yourself you need something like this:<br /><br /> result = SELECT MAX(FIELD1) FROM MySQLTable;<br /><br /> if result = Null then<br /> MyNextRecordNumber = 1<br /> else<br /> MyNextRecordNumber = (result + 1)<br /><br />This will most likely not work at all, (it is only pseudo code), but it gives you an idea of how to tackle the problem.<!--content-->
thanks...I ended up using the max funciton u stated above....<br /><br />Thanks anyway.<!--content-->
 
Back
Top