Jump to content

Msyql Efficiency Help


section31

Recommended Posts

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

a very simple mysql table...

TABLE urls

->FIELD1 INT "id" this is set to primary and autoincrement

->FIELD2 VARCHAR "urls"

 

what would be the most efficient 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.

 

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

 

thanks,

Dave

Link to comment
Share on other sites

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.

 

If you want to handle the auto increment yourself you need something like this:

 

result = SELECT MAX(FIELD1) FROM MySQLTable;

 

if result = Null then

MyNextRecordNumber = 1

else

MyNextRecordNumber = (result + 1)

 

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...