/*
環境 :
本地(xp+sql2005):
select @@version
icrosoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
data伺服器(win2000+sql2000):
select @@version
Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)
May 3 2005 23:18:38
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
*/
-- 1 建立連結的伺服器
exec sp_addlinkedserver 'data', '', 'SQLOLEDB','192.168.102.208'
exec sp_addlinkedsrvlogin 'data','false ',null, 'sa', 'sa'
go
-- 2 建立測試過程
if object_id('p_test') is not null drop proc p_test
go
create proc p_test @sql varchar(8000)
as
begin
exec(@sql)
end
-- 3 測試
declare @sql varchar(8000)
set @sql ='
delete from data.master.dbo.tb
insert data.master.dbo.tb (item) values(''AAAAAAAAAA'')
select item from data.master.dbo.tb'
exec p_test @sql
/*
(1 行受影響)
(1 行受影響)
item
----------------------------------------------------------------------------------------------------
AAAAAAAAAA
(1 行受影響)
*/
-- 4 刪除連結
exec sp_dropserver 'data ', 'droplogins'