PDA

View Full Version : [Urgent, HELP!]Using Trigger to check duplicate


Ayaka
09-23-2008, 09:25 PM
Hi! I'm new in using Trigger for my database. I am currently using MySQL 5.0 Query Browser and i would like to create trigger within the browser. Here's my code


CREATE TRIGGER check_OrderID BEFORE INSERT ON DELIVERY
FOR EACH ROW
BEGIN
IF(orderID!=NEW.OrderID)
THEN
INSERT INTO DELIVERY(DeliveryID,OrderID,DriverID,DeliveryVID)
VALUES(NEW.DeliveryID,NEW.OrderID,NEW.DriverID,NEW .DeliveryVID);
END;

Actually I want to check if the OrderID to be inserted is already in the Delivery table, then that insertion is to ba aborted, if not, it will just continue with the insertion.

BargainPredator
09-27-2008, 12:18 AM
I'm sure this is going to disapoint you. I was when i realised this.

But in Mysql 5.0 you cannot insert or delete a row in the same table that the trigger is set on.

Wich is wath you are doing on the table DELIVERY.

It's MySql conseptors made it that way to avoid Stack overflow.

The same goes for Stored procedures that can't call themself

Sorry