当我在回复表新增数据 我就会执行下列语句
触发器在mysql的使用过DELIMITER $$开头 END; $$ 结尾,注意 触发的语句必须用;结尾
创建触发器
DELIMITER $$
CREATE TRIGGER comment_Trigger1
AFTER INSERT ON reply
FOR EACH ROW
BEGIN
UPDATE COMMENT
SET replyid= (SELECT COUNT(*) FROM reply WHERE reply.commentid = new.commentid )
WHERE commentid=new.commentid;
END;
$$
DELIMITER $$
CREATE TRIGGER 触发器名
BEFORE|AFTER DELETE|INSERT|UPDATE
ON 表名 FOR EACH ROW
BEGIN
触发SQL代码块;
END;
$$
--触发器删除评论 回复清空
DELIMITER $$
CREATE TRIGGER commentDelete
BEFORE DELETE ON COMMENT
FOR EACH ROW
BEGIN
DELETE FROM reply WHERE old.commentid;
END;
$$
SHOW TRIGGERS --查看触发器
DROP TRIGGER commentDelete --删除触发器
UPDATE COMMENT
SET replyid= (SELECT COUNT(*) FROM reply WHERE reply.commentid = new.commentid )
WHERE commentid=new.commentid;
END;
$$
DELIMITER $$
CREATE TRIGGER 触发器名
BEFORE|AFTER DELETE|INSERT|UPDATE
ON 表名 FOR EACH ROW
BEGIN
触发SQL代码块;
END;
$$
--触发器删除评论 回复清空
DELIMITER $$
CREATE TRIGGER commentDelete
BEFORE DELETE ON COMMENT
FOR EACH ROW
BEGIN
DELETE FROM reply WHERE old.commentid;
END;
$$
SHOW TRIGGERS --查看触发器
DROP TRIGGER commentDelete --删除触发器