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