mysql触发器创建、编辑

阅读更多

mysql触发器

 

 

drop trigger if exists tg_bb_insert;
delimiter $$
create trigger tg_bb_insert
before insert on bb
FOR EACH ROW
BEGIN
    declare ishave int;
    select 1 into ishave from cc where cc.name = NEW.name;
    if ishave is null then
        insert into cc(`name`) values(NEW.name);
    elseif ishave = 1 then
		update cc set cc.name_repeat_count = cc.name_repeat_count + 1 where cc.name = NEW.name;
	else
		-- do nothing --  
		set @tmp=1;
    end if;
END$$
delimiter ;
 

 

你可能感兴趣的:(mysql,触发器,例子,创建,编辑)