如何用存储过程实现两个表同步?

现在又两个表分别是A表( a ,b , c ,d , e ,f) B表(a,b,c,d)现在点击同步按钮,将A表的数据复制到B表,A,B两个同字段的,数据使用A表的数据(A,B当然通过主键关联),如果说A.a = B.a 剩下A表的数据要全部插入到B表!

牧羊人nacy
浏览 795回答 6
6回答

喵喔喔

update set B b=A.b,c=A.c,d=A.d from A where B.a=A.a insert into B(a,b,c,d) select A.a,A.b,A.c,A,d from A where A.a not in(select a from B) for c in (select a,b,c,d from A left join B on A.a=B.a) loop update B set b=c.b,c=c.c,d=c.d where a=c.a; end loop;insert into B(a,b,c,d) select A.a,A.b,A.c,A,d from A where A.a not in(select a from B);

喵喵时光机

update set B b=A.b,c=A.c,d=A.d from A where B.a=A.a insert into B(a,b,c,d) select A.a,A.b,A.c,A,d from A where A.a not in(select a from B) for c in (select a,b,c,d from A left join B on A.a=B.a) loop update B set b=c.b,c=c.c,d=c.d where a=c.a; end loop;insert into B(a,b,c,d) select A.a,A.b,A.c,A,d from A where A.a not in(select a from B);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server