1、删除 在base_student表设置触发器,删除学生时触发删除wx_student的数据
begin
delete from wx_student where id=old.id;
end
2、更新/插入
base_student 插入/或者更新学生数据 wx_student 同步生成
begin
DECLARE num int;
SELECT count(*) into num FROM wx_student WHERE id=new.id; #查询是否存在该学生
if num>0 then #数量大于0已存在,做更新操作
UPDATE wx_student SET
idcard=new.idcard,xjh=new.xjh,real_name=new.real_name,tfk=new.tfk,
grade_fk=new.grade_fk,class_id=new.class_id
WHERE id=new.id;
else # 插入数据
INSERT into
wx_student(id,idcard,xjh,real_name,tfk,grade_fk,class_id)
SELECT id,idcard,xjh,real_name,tfk,grade_fk,class_id FROM base_student where id=new.id;
end if;
end
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!