可以通过sql触发器来实现。
例下列触发器代码 :
create trigger tri_kszb_insert
on ygpx_kszb --操作的表名
for insert --给表插入一条数据的时候触发
as
declare @kssj datetime
declare @sqbh char(40)
select @kssj = kssj,@sqbh = sqbh from inserted --把插入的数据的保存到变量
insert into ygpx_kszb2 values (@kssj,@sqbh) --同步插入到另一表
以上触发器可以实现,在表ygpx_kszb中插入数据,同步插入到表ygpx_kszb2 。
触发器还可以针对表的 insert,delete, update 操作时安装要求执行数据同步的操作,即可实现两个表里的数据同步。
1.触发器
create trigger tr_tong_bu on tb1
for insert,update,delete
as
begin
if (select count(*) from inserted )+(select count(*) from deleted)>0
begin
update tb2
set text3=inserted.text1,text4=inserted.text2
from tb2 join deleted d on tb2.text3=d.text1 and tb2.text4=d.text2
end
if (select count(*) from inserted )>0 and (select count(*) from deleted)=0
begin
insert into tb2 select * from inserted
end
if (select count(*) from inserted )=0 (select count(*) from deleted)>0
begin
delete tb2 from deleted d ,tb2 where d.text1=tb2.text3 and d.text2=tb2.text4
end
end
2.sql server2008 可以使用Merge 实现表同步
自己看列子:http://blog.csdn.net/feixianxxx/archive/2010/02/07/5296519.aspx
用个关系表