Autonummering terugophalen

Pagina: 1
Acties:
  • 93 views sinds 30-01-2008

  • mark_gl
  • Registratie: September 2001
  • Laatst online: 24-08 08:45
Ik post werknemer gegevens in asp, die door sql een automatisch ID krijgt. Nu heb ik ditzelfde ID direct erna nodig. Hoe haal ik deze op zodat ik zeker weet dat ik niks fout kan gaan.

Oplossing via select max(id) geprobeerd, werkt goed, maar zit nog altijd een klein risico in dat iemand anders op het zelfde moment post en dus dat ik het verkeerde id terug krijg. Weet iemand een waterdichte oplossing?

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

mysql
code:
1
SELECT LAST_INSERT_ID() FROM tabel

of

php
code:
1
mysql_insert_id();

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • MrBrown
  • Registratie: Augustus 2000
  • Laatst online: 11-06 15:51

MrBrown

Reservoir Dog

@@IDENTITY voor sql server
bv:
code:
1
2
INSERT INTO Table(field1, field2) VALUES('value1', 'value2')
SELECT @@IDENTITY AS Ident

Powered by Manetti (compiled by Jura)


Verwijderd

en in Access???

  • whoami
  • Registratie: December 2000
  • Laatst online: 22:42
In Access kan je het ook doen dmv @@identity

In SQL Server heb je ook nog Scope_Identity en Ident_Current

Over welke database hebben we het hier eigenlijk? Dat had je beter vermeld in je topictitel.

[ Voor 39% gewijzigd door whoami op 21-01-2003 13:51 ]

https://fgheysels.github.io/


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Thursday 22 November 2001 16:04
:D

antwoord staat in topic

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz

Pagina: 1

Dit topic is gesloten.