Avatar billede holmqvist Nybegynder
25. februar 2005 - 09:27 Der er 4 kommentarer og
1 løsning

What's the auto_index

When using auto increment, how can you through an SQL-query see either
1. the next auto_index or
2. the auto_index you just used or
3. the line you just inserted
Avatar billede webcreator Nybegynder
25. februar 2005 - 09:50 #1
You should be capable of calculating these things by selecting the latest post in your database.

1) the next auto index : last index + 1
2) just select the latest post
Avatar billede webcreator Nybegynder
25. februar 2005 - 09:51 #2
Of cause this is not a good solution if you have several users on your database.
Avatar billede -mundi- Nybegynder
25. februar 2005 - 09:54 #3
"select @@identity as thenewid" returns the last autoincrement number created on your current connection. (in access and msSQL)
Avatar billede holmqvist Nybegynder
25. februar 2005 - 10:25 #4
mundi:
I'm using a MYSQL database.

webcreator:
"2)just select the latest post"
Yes, that would work, but my question is how. How does the SQL-query for getting the latest post look like?
Avatar billede -mundi- Nybegynder
25. februar 2005 - 10:31 #5
use LAST_INSERT_ID() for mySQL

its 2 statements:
first the insert
then the LAST_INSERT_ID()
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester