0
I am looking for a solution to solve my problem. When I ask for 2 items of the same type on my site it inserts 2 times the same item. I already tried to create a TRIGGER with AFTER INSERT to check if there is already that order number but without success
I’ve already tried: INSERT INTO Lojas.dbo.ComprasSucc (Usuario,Codigo_Produto,Quantidade,Numero_Pedido,Produto_Name,Data) VALUES (?,?,?,?,?,GETDATE()) ON DUPLICATE KEY UPDATE Numero_Pedido=Numero_Pedido+1
in my website’s PHP code too but it can’t send.
I would like to check if there is already an equal order number within the table before inserting. I tried: IF NOT EXISTS (SELECT Numero_Pedido FROM ComprasSucc WHERE Numero_Pedido = @Numero_Pedido)
But I couldn’t get him to check if it actually existed. I don’t know enough about SQL Server.
The order numbers that are sent to the database are Andom (Random).
also tried MAX(ID) but if you place 2 different orders at the same time it only performs the last.
Have you ever thought of defining
Numero_Pedido
as the primary key in the tableComprasSucc
?– anonimo
Only one can and my table already has a main ;(
– Mercurio
In this case, Constraint UNIQUE will solve.
– anonimo
I tried but when I make 2 purchase in the same cart it generates the same Order Number ID so it is sent only 1
– Mercurio
All indicates that this is a problem of your application and not the database.
– anonimo