DROP TRIGGER IF EXISTS before_delete_concept_access;
DELIMITER //
CREATE TRIGGER before_delete_concept_access
BEFORE DELETE ON `concept_access` FOR EACH ROW
BEGIN
IF (SELECT COUNT(*) FROM concept_access_log WHERE map=OLD.map
AND accesstype=OLD.accesstype AND startdate=OLD.startdate AND stopdate=OLD.stopdate) = 0 THEN
INSERT INTO concept_access_log (map, accesstype, startdate, stopdate)
VALUES (OLD.map, OLD.accesstype, OLD.startdate, OLD.stopdate);
END IF;
END//
DELIMITER ;
Saya tidak menggunakan not exists
, cukup uji apakah jumlah kecocokan lebih besar dari 0
kode Anda berjalan dengan baik di komputer saya, apa versi MySQL Anda?
mysql> select version();
+------------+
| version() |
+------------+
| 5.1.56-log |
+------------+
1 row in set (0.00 sec)