国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
通過(guò)觸發(fā)器實(shí)現(xiàn)數(shù)據(jù)庫(kù)的即時(shí)同步

通過(guò)觸發(fā)器實(shí)現(xiàn)數(shù)據(jù)庫(kù)的即時(shí)同步

[日期:2005-07-08]來(lái)源:CSDN  作者:[字體: ]

--即時(shí)同步兩個(gè)表的實(shí)例:

--測(cè)試環(huán)境:SQL2000,遠(yuǎn)程主機(jī)名:xz,用戶名:sa,密碼:無(wú),數(shù)據(jù)庫(kù)名:test

--創(chuàng)建測(cè)試表,不能用標(biāo)識(shí)列做主鍵,因?yàn)椴荒苓M(jìn)行正常更新
--在本機(jī)上創(chuàng)建測(cè)試表,遠(yuǎn)程主機(jī)上也要做同樣的建表操作,只是不寫觸發(fā)器
if exists (select * from dbo.sysobjects where id = object_id(N‘[test]‘) and OBJECTPROPERTY(id, N‘IsUserTable‘) = 1)
drop table [test]

create table test(id int not null constraint PK_test primary key
 ,name varchar(10))
go

--創(chuàng)建同步的觸發(fā)器
create trigger t_test on test
for insert,update,delete
as
set  XACT_ABORT on
--啟動(dòng)遠(yuǎn)程服務(wù)器的MSDTC服務(wù)
exec master..xp_cmdshell ‘isql /S"xz" /U"sa" /P"" /q"exec master..xp_cmdshell ‘‘net start msdtc‘‘,no_output"‘,no_output

--啟動(dòng)本機(jī)的MSDTC服務(wù)
exec master..xp_cmdshell ‘net start msdtc‘,no_output

--進(jìn)行分布事務(wù)處理,如果表用標(biāo)識(shí)列做主鍵,用下面的方法
BEGIN DISTRIBUTED TRANSACTION
delete from openrowset(‘sqloledb‘,‘xz‘;‘sa‘;‘‘,test.dbo.test)
 where id in(select id from deleted)
insert into openrowset(‘sqloledb‘,‘xz‘;‘sa‘;‘‘,test.dbo.test)
 select * from inserted
commit tran
go

--插入數(shù)據(jù)測(cè)試
insert into test
select 1,‘a(chǎn)a‘
union all select 2,‘bb‘
union all select 3,‘c‘
union all select 4,‘dd‘
union all select 5,‘a(chǎn)b‘
union all select 6,‘bc‘
union all select 7,‘ddd‘

--刪除數(shù)據(jù)測(cè)試
delete from test where id in(1,4,6)

--更新數(shù)據(jù)測(cè)試
update test set name=name+‘_123‘ where id in(3,5)

--顯示測(cè)試的結(jié)果
select * from test a full join
openrowset(‘sqloledb‘,‘xz‘;‘sa‘;‘‘,test.dbo.test) b on a.id=b.id

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
基于SQL SERVER觸發(fā)器技術(shù)的實(shí)現(xiàn)
如何用觸發(fā)器實(shí)現(xiàn)記錄數(shù)據(jù)庫(kù)表和記錄更改日志的操作
SQL Server的C#連接及對(duì)象存在判斷
利用oracle快照dblink解決數(shù)據(jù)庫(kù)表同步問(wèn)題 - - JavaEye技術(shù)網(wǎng)站
簡(jiǎn)單三步輕松實(shí)現(xiàn)ORACLE字段自增
兩個(gè)oracle數(shù)據(jù)庫(kù)間通過(guò)數(shù)據(jù)庫(kù)鏈接和觸發(fā)器同步兩個(gè)數(shù)據(jù)庫(kù)間數(shù)據(jù)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服