触发器和存储过程实现2张表的同步
表A(userid,username,department,mark)
表B(userid,department)
分别使用触发器和存储过程实现表A中的userid,department同步到表B相应字段?
数据库方面不太好,求源码和注释
------最佳解决方案--------------------都不结贴的话,就没有了答疑的动力了。
------其他解决方案--------------------请大神们 帮帮忙
------其他解决方案--------------------create or replace trigger trig_on_A
after insert or update or delete on A
for each row
begin
if inserting then
insert into B values(:new.userid,:new.department);
end if;
if updating(userid,department) then
update B set userid=:new.userid,:new.department where userid=:old.userid;
end if;
if deleting then
delete from B where userid=:old.userid
end if;
end trig_on_A;
------其他解决方案--------------------update B set userid=:new.userid,:new.department where userid=:old.userid;
应为:
update B set userid=:new.userid,department=:new.department where userid=:old.userid;