[sql server][基础] 链接服务器

/*
环境 :

本地(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'

你可能感兴趣的:(SQL Server)