Page 1 of 1

auto increment MySQL

Posted: Sun Nov 30, 2014 6:50 pm
by Da_Elf
i ant to find the next auto increment number
currently with livecode im using SELECT MAX(id) FROM database then adding 1 to it to get the next id that will be used.
however what if i have 6 items, the next to be used will be 7. but if i delete item 6 from the database using my method will give me 6 as the next available one however MySQL will set the next entry as 7

Re: auto increment MySQL

Posted: Sun Nov 30, 2014 10:34 pm
by SparkOut
Select max(id) after you do the insert? Or perhaps LAST_INSERT_ID()

Re: auto increment MySQL

Posted: Mon Dec 01, 2014 7:55 pm
by Da_Elf
that works at that point in time. but what if i go do other stuff. Log off the come back then need to find it. I would have to insert something to get the AI number

Re: auto increment MySQL

Posted: Mon Dec 01, 2014 8:29 pm
by bangkok
What about :

Code: Select all

SHOW TABLE STATUS WHERE Name = 'yourtable'
It will gives you infos on the table... with "auto increment" = the next value

Re: auto increment MySQL

Posted: Tue Dec 02, 2014 3:34 am
by Da_Elf
thanks. This works

Code: Select all

   put "SHOW TABLE STATUS WHERE Name = 'users' " into xSQL
   put revDataFromQuery(comma, cr, gConnectionID, xSQL) into maxData
   set itemDelimiter to comma
   answer item 11 of maxData