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.
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.