创建链接服务器储存过程

 /****** 对象:  StoredProcedure [dbo].[UpdateLinkedServer]    脚本日期: 11/26/2009 09:32:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROC [dbo].[UpdateLinkedServer] @LinkedServerName nvarchar(50), @SourceServerName nvarchar(50), @LoginName nvarchar(50), @Password nvarchar(50)
AS
BEGIN
 
    EXEC('IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0 AND srv.name = N''' + @LinkedServerName + ''') ' +
         'EXEC master.dbo.sp_dropserver @server=N''' + @LinkedServerName + ''', @droplogins=''droplogins''')
    EXEC('
 EXEC master.dbo.sp_addlinkedserver @server = N''' + @LinkedServerName + ''', @srvproduct='''', @provider=N''SQLOLEDB'', @datasrc=N''' + @SourceServerName+ ''' ' +
 'EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N''' + @LinkedServerName + ''',@useself=N''False'',@locallogin=NULL,@rmtuser=N''' + @LoginName + ''',@rmtpassword=''' + @Password + ''' '
    )
END

Exec [UpdateLinkedServer] 'BS','192.168.61.3','VIPUSER','2009VIP_user'

SELECT SPDM,SPMC FROM BS.J2009.dbo.shangpin where FJSX2 ='2A3002'

SELECT * FROM BS.J2009.dbo.FJSX2 Order by SXDm

SELECT * FROM BS.J2009.dbo.FJSX6 where sxdm like '%3003'
3003
SELECT * FROM BS.J2009.dbo.DALEI

你可能感兴趣的:(server,服务器,脚本,user,null)