创建链接数据库方式的步骤在这里不重复说明,很多地方都有资料!
CREATE TRIGGER TransferMTMessage ON [dbo].[T_DWS_MT_Message]
FOR INSERT
AS
-- 必须设置这个选项目,否则出现 OLE DB 错误跟踪
--[OLE/DB Provider 'MSDAORA' ITransactionLocal::StartTransaction returned 0x8004d013: ISOLEVEL=4096
--解决异构服务器的触发器 参考:http://support.microsoft.com/default.aspx?scid=kb;EN-US;280106
clearcase/" target="_blank" >cc0000>SET XACT_ABORT ON
Declare @Seq int
Declare @LinkID varchar(20)
Declare @Content varchar(140)
Declare @Mobile varchar(20)
--Step1: 从Oracle数据库获取一个序列的nextval
Select @Seq=(Select * from openquery(hnoracle,'Select Seq.nextval From dual'))
--Step2: 获取新插入的数据
Select @LinkID=LinkID From INSERTED
Select @Content=SMS_Content From INSERTED
Select @Mobile=MT_Mobile From INSERTED
--Step3:将数据通过链接数据库写进Oracle数据库
INSERT INTO [hnoracle]..[HAILINE].[MTMESSAGE](MTMSGID,MTMOBILE,CONTENT,LINKID,STATUS,SENDTIME,SPFLAG)
Values(@Seq, @Mobile, @Content, @LinkID,0,NULL,NULL)
--Step4:删除本地SQLServer下行信息
Delete From T_DWS_MT_Message Where ID IN( Select ID From INSERTED)
Return