正如@mabi在评论中所提到的 – 括号中存在语法错误.以下修改后的代码适用于我:
DELIMITER #
CREATE TRIGGER insert_guid
BEFORE INSERT ON guid_tool
FOR EACH ROW
BEGIN
SET NEW.guid_key = UUID();
END;
#
DELIMITER ;
测试出来:
mysql> INSERT INTO guid_tool (ID) VALUES (1);
Query OK, 1 row affected, 1 warning (0.04 sec)
mysql> SELECT * FROM guid_tool;
+----+--------------------------------------+
| ID | guid_key |
+----+--------------------------------------+
| 1 | a0467ebf-5c4f-11e3-903a-6cccbb4423e3 |
+----+--------------------------------------+
1 row in set (0.00 sec)