create table [user](id int primary key,number varchar(4),name varchar(10)) go
--以下在局域网(本机操作)
--本机的表,state说明:null 表示新增记录,1 表示修改过的记录,0 表示无变化的记录
if exists (select * from dbo.sysobjects where id = object_id(n'[user]') and objectproperty(id, n'isusertable') = 1) drop table [user] go create table [user](id int identity(1,1),number varchar(4),name varchar(10),state bit) go
--创建触发器,维护state字段的值
create trigger t_state on [user] after update as update [user] set state=1 from [user] a join inserted b on a.id=b.id where a.state is not null go
--为了方便同步处理,创建链接服务器到要同步的服务器
--这里的远程服务器名为:xz,用户名为:sa,无密码
if exists(select 1 from master..sysservers where srvname='srv_lnk') exec sp_dropserver 'srv_lnk','droplogins' go exec sp_addlinkedserver 'srv_lnk','','sqloledb','xz' exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'sa' go
--创建同步处理的存储过程
if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[p_synchro]') and objectproperty(id, n'isprocedure') = 1) drop procedure [dbo].[p_synchro] go create proc p_synchro as --set xact_abort on