mysql>delimiter //
->create trigger sitedata_ins2
->before insert on user
->for each row
->Begin
->If not exists(select 1 from user_data where d_id=new.id) then
->insert into user_data(d_id,d_name) values(new.id,new.name)
->END IF
->end//
->delimiter
或者简单一点:
mysql>delimiter //
->create trigger sitedata_ins2
->before insert on user
->for each row
->Begin
->insert into user_data(d_id,d_name) values(new.id,new.name)
->end//
->delimiter
二种方法都可以,建议你用第一种
不知你用的是什么查询分析器。我记得 select count(*) into @cnt from table1 where map_id = 114 and `type` = 400
if @cnt >0 then update table1 set `count` = 25 where map_id = 114 and `type` = 400
else
insert table1 (map_id,`count`,`type`) values (114,25,400)
end if
而且好像if then endif只能在procedure或是function里用吧
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)