语法:
create trigger triggerName after/before insert/update/delete on 表名 for each row #这句话在mysql是固定的 begin sql语句; end;
例子:
DROP TRIGGER IF EXISTS `category_insert`;
DELIMITER $$
CREATE TRIGGER category_insert BEFORE INSERT ON category FOR EACH ROW
BEGIN
IF
new.parent_id = 0 THEN
SET new.path = new.category_name,
new.idpath = ( SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'category' );
ELSE
SET new.path = CONCAT( new.path, ",", new.category_name ),
new.idpath = CONCAT( new.idpath, ",", ( SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'category' ) );
END IF;
END $$
DELIMITER;