sql server 跨資料庫插入資料

來源:互聯網
上載者:User

標籤:

建立伺服器的串連,建立好後可以存在伺服器上,可以在不同位置重複使用,和系統函數類似

exec sp_addlinkedserver ‘RemoteServer‘, ‘‘, ‘SQLOLEDB ‘, ‘192.168.3.225‘ exec sp_addlinkedsrvlogin ‘RemoteServer‘, ‘false ‘,null, ‘sa‘, ‘[email protected]‘ 

刪除串連

exec sp_dropserver ‘RemoteServer‘, ‘droplogins‘ 

 

使用方法:(串連.資料庫.dbo.表)

select top 100 * from  RemoteServer.Suncome.dbo.AkEL

 

下面通過觸發器調用

create trigger syncBarcode on BarcodeCompInfoafter update,insertasdeclare @Barcode nvarchar(50)select @Barcode=Barcode from inserteddeclare @num int--用於判斷上面的編號是不是存在於BdVendor表中,來推斷添加還是修改select @num=COUNT(*) from RemoteServer.Suncome.dbo.AkBarcodeCompInfo where Barcode=@Barcodeif @num=0begin  insert into RemoteServer.Suncome.dbo.AkBarcodeCompInfo(Barcode,OrderNumber,PrintDate,LineCode)  select [Barcode],[WorkOrderID],[PrintDate],[BC] from insertedend

 

然而並沒有什麼卵用啊

右鍵點擊“我的電腦”--“管理”--“服務和應用程式”--“服務”---啟動“Distributed Transaction Coordinator”服務,啟動分布式服務後還要開啟遠程伺服器以及本機伺服器135連接埠,因為遠程分布式服務需要該連接埠通訊。
1:開啟“控制台”--“管理工具”--“元件服務”
2:在“電腦”下右擊“我的電腦”--“屬性”--選擇“MSDTC”選項卡
3:點擊“安全性配置”按鈕,
4:網路DTC訪問勾選上,允許遠程用戶端,允許遠端管理,允許入站,
允許出站,不要求身分識別驗證勾選上。
注意:以上步驟需要兩台伺服器都要配置。

 

sql server 跨資料庫插入資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.