一 创建触发器

    MYSQL软件在触发如下语句时,就会自动执行所设置的操作;

        DELETE 语句

        INSERT 语句

        UPDATE 语句

    create trigger trigger_name

        before|after trigger_EVENT

            on table_name for each row trigger_STMT;

    trigger_STMT: 表示激活触发器后被执行的语句。

    示例1:单条执行语句的触发器

    create trigger tri_diarytime

        before insert

            on t_dept for each row

                insert into t_diary values(null,'t_dept',now());

    示例2:创建包含多条执行语句的触发器

        delimiter $$

        create trigger trigger_name

            before|after trigger_event

                on table_name for each row

                    begin

                        trigger_STMT

                    end

        

        delimiter $$

        create trigger tri_diarytime2

            after insert

                on t_dept for each row

                    begin

                        insert into t_diary values(null,'t_dept',now());

                        insert into t_diary values(null,'t_dept',now());

                    end

                    $$

        delimiter ;

二:查看触发器

    SHOW TRIGGERS;

三:删除触发器

    DROP TRIGGER trigger_name;