代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
MSSQL
】
批量导出当前实例下的所有linkedserver
作者:
天星
/ 发布于
2014/11/4
/
932
-- ============================================= -- Author: <桦仔> -- Blog: <http://www.cnblogs.com/lyhabc/> -- Create date: <2014/11/3> -- Description: <批量导出实例下所有linkedserver> -- LINK: http://msdn.microsoft.com/zh-cn/library/ms189811.aspx -- ============================================= SET NOCOUNT ON USE [master] GO DECLARE @servername NVARCHAR(2000) DECLARE @id INT DECLARE @scriptdate NVARCHAR(200) DECLARE @productName NVARCHAR(2000) DECLARE @datasource NVARCHAR(4000) DECLARE @useself BIT DECLARE @dist BIT DECLARE @remoteuser NVARCHAR(2000) DECLARE @collationcompatible BIT DECLARE @dataaccess BIT DECLARE @sub BIT DECLARE @pub BIT DECLARE @rpc BIT DECLARE @rpcout BIT DECLARE @connecttimeout BIGINT DECLARE @lazyschemavalidation BIT DECLARE @querytimeout BIGINT DECLARE @useremotecollation BIT DECLARE @remoteproctransactionpromotion BIT DECLARE LinkserverNameCur CURSOR FOR SELECT srv.name AS [Name] , CAST(srv.server_id AS INT) AS [ID] FROM sys.servers AS srv WHERE ( srv.server_id != 0 ) OPEN LinkserverNameCur FETCH NEXT FROM LinkserverNameCur INTO @servername, @id WHILE @@FETCH_STATUS = 0 BEGIN SELECT @servername = srv.name , @datasource = ISNULL(srv.data_source, N'''') , @productName = srv.product , @collationcompatible = CAST(srv.is_collation_compatible AS BIT) , @dataaccess = CAST(srv.is_data_access_enabled AS BIT) , @dist = CAST(srv.is_distributor AS BIT) , @pub = CAST(srv.is_publisher AS BIT) , @rpc = CAST(srv.is_remote_login_enabled AS BIT) , @rpcout = CAST(srv.is_rpc_out_enabled AS BIT) , @sub = CAST(srv.is_subscriber AS BIT) , @connecttimeout = srv.connect_timeout , @lazyschemavalidation = srv.lazy_schema_validation , @querytimeout = srv.query_timeout , @useremotecollation = srv.uses_remote_collation , @remoteproctransactionpromotion = CAST(srv.is_remote_proc_transaction_promotion_enabled AS BIT) FROM sys.servers AS srv WHERE ( srv.server_id != 0 ) AND ( srv.name = @servername ) AND ( srv.[server_id] = @id ) SELECT @remoteuser = ISNULL(ll.remote_name, N'') , @useself = CAST(ll.uses_self_credential AS BIT) FROM sys.servers AS srv INNER JOIN sys.linked_logins ll ON ll.server_id = CAST(srv.server_id AS INT) LEFT OUTER JOIN sys.server_principals sp ON ll.local_principal_id = sp.principal_id WHERE ( ( srv.server_id != 0 ) AND ( srv.name = @servername) ) IF (@servername IS NOT NULL AND @id IS NOT NULL) BEGIN SELECT @scriptdate=CONVERT(NVARCHAR(200),GETDATE(),120) PRINT '/*************************************SCRIPT FOR LINKED SERVER: ['+@servername+']****************************************************/' PRINT '/********************************************************************************************************************************/' PRINT 'USE [master]'+CHAR(13)+'GO' PRINT '/****** Object: LinkedServer ['+@servername+'] Script Date: '+@scriptdate+' ******/' PRINT 'EXEC master.dbo.sp_addlinkedserver @server = N'''+@servername+''', @srvproduct=N'''+@productName+'''' PRINT '/* For security reasons the linked server remote logins password is changed with ######## */' DECLARE @sql NVARCHAR(2000) IF (@remoteuser IS NOT NULL AND @remoteuser != N'') BEGIN SET @sql='EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'''+@datasource+''',@useself=N'''+CASE @useself WHEN 0 THEN 'false' ELSE 'true' END +''',@locallogin=NULL,@rmtuser=N'''+@remoteuser+''',@rmtpassword=''########''' END ELSE BEGIN SET @sql='EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'''+@datasource+''',@useself=N'''+CASE @useself WHEN 0 THEN 'false' ELSE 'true' END +''',@locallogin=NULL,@rmtuser=N'''',@rmtpassword=''########''' END PRINT @sql PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''collation compatible'', @optvalue=N'''+CASE @useself WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''data access'', @optvalue=N'''+CASE @dataaccess WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''dist'', @optvalue=N'''+CASE @dist WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''pub'', @optvalue=N'''+CASE @pub WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''rpc'', @optvalue=N'''+CASE @rpc WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''rpc out'', @optvalue=N'''+CASE @rpcout WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''sub'', @optvalue=N'''+CASE @sub WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''connect timeout'', @optvalue=N'''+CAST(@connecttimeout AS NVARCHAR(200))+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''lazy schema validation'', @optvalue=N'''+CASE @lazyschemavalidation WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''query timeout'', @optvalue=N'''+CAST(@querytimeout AS NVARCHAR(200))+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''use remote collation'', @optvalue=N'''+CASE @useremotecollation WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT 'EXEC master.dbo.sp_serveroption @server=N'''+@servername+''', @optname=N''remote proc transaction promotion'', @optvalue=N'''+CASE @remoteproctransactionpromotion WHEN 0 THEN 'false' ELSE 'true' END+'''' PRINT 'GO' PRINT '/********************************************************************************************************************************/' PRINT '/********************************************************************************************************************************/' PRINT CHAR(13) PRINT CHAR(13) PRINT CHAR(13) END FETCH NEXT FROM LinkserverNameCur INTO @servername, @id END CLOSE LinkserverNameCur DEALLOCATE LinkserverNameCur
试试其它关键字
批量导出
linkedserver
同语言下
.
SQL查询 多列合并成一行用逗号隔开
.
查看存储过程修改时间,最近执行时间
.
设置手动批量删除数据库相关进程
.
获取某个表中特定字段的所有字符串形式
.
SQL 如何去除重复的字符串
.
怎么去掉一个字段中的重复数据
.
String 去除空格 回车 换行 水平制表符
.
SQL查询和替换含有回车,空格,TAB
.
SQL SERVER 查询每日新增用户数量、次留数量
.
判断两个字符串是否存在相同的内容
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
天星
贡献的其它代码
(
31
)
.
生成仿银行卡的会员号
.
MyBatis基本查询、条件查询、查询排序
.
撒列实现关键字过虑
.
jsonp跨域请求C# webform页面的数据
.
定积分计算(Romberg)
.
android Gridview九宫的效果实现
.
实现动态数组,克服静态数组大小固定
.
计算一个数的平方根
.
计算厄密多项式
.
将字符串转换为整数
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3