2
In a sales system I realize a INSERT
registering the cover of the order (order without the items) soon after the cover registration SELECT MAX
to return the last id inserted to use this id as Foreign key when inserting items in the items table.
INSERT INTO CAPAPEDIDO VALUES (123,GETDATE());
SELECT MAX(CodPedido) AS LastID FROM CAPAPEDIDO;
INSERT INTO PEDIDO_ITEM(CodPedido,CodProduto,Qtd,VrUnit,TotItem) VALUES ($lastId ,$codProduto,$qtdProduto,$valorProduto,$totItem);
this is exemplified the process I use.
the doubt is if there are several requests happening simultaneously there would be conflict in Lastid no 2 SELECT MAX
? the items could be registered in another order cover?
thinking of more than 3,000 orders at the same time.
what would be the solution?
help! thanks
See if this helps https://stackoverflow.com/questions/10680943/pdo-get-the-last-id-inserted
– Marcos Xavier