日期:2014-05-16  浏览次数:20946 次

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 ;
?

?