createtable[user](idintprimarykey,numbervarchar(4),namevarchar(10))
go
--以下在局域网(本机操纵)
--本机的表,state申明:null暗示新增纪录,1暗示修正过的纪录,0暗示无变更的纪录
ifexists(select*fromdbo.sysobjectswhereid=object_id(N[user])andOBJECTPROPERTY(id,NIsUserTable)=1)
droptable[user]
GO
createtable[user](idintidentity(1,1),numbervarchar(4),namevarchar(10),statebit)
go
--创立触发器,保护state字段的值
createtriggert_stateon[user]
afterupdate
as
update[user]setstate=1
from[user]ajoininsertedbona.id=b.id
wherea.stateisnotnull
go
--为了便利同步处置,创立链接服务器到要同步的服务器
--这里的远程服务器名为:xz,用户名为:sa,无暗码
ifexists(select1frommaster..sysserverswheresrvname=srv_lnk)
execsp_dropserversrv_lnk,droplogins
go
execsp_addlinkedserversrv_lnk,,SQLOLEDB,xz
execsp_addlinkedsrvloginsrv_lnk,false,null,sa
go
--创立同步处置的存储历程
ifexists(select*fromdbo.sysobjectswhereid=object_id(N[dbo].[p_synchro])andOBJECTPROPERTY(id,NIsProcedure)=1)
dropprocedure[dbo].[p_synchro]
GO
createprocp_synchro
as
--setXACT_ABORTon