是否有“如果存在"的提示?测试链接服务器? [英] Is there an "IF EXISTS" test for a linked server?
本文介绍了是否有“如果存在"的提示?测试链接服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够以编程方式(在T-SQL中)检查当前服务器和数据库是否已存在特定的链接服务器(这样,如果该链接尚不存在,则可以创建它).我尝试过这样的事情:
I want to be able to programmatically (in T-SQL) check if a specific linked server already exists for my current server and database (so that if the link doesn't exist yet, I can create it). I tried stuff like this:
IF OBJECT_ID('myserver\devdb_1') IS NULL
BEGIN
PRINT 'Does not exist, need to create link'
EXEC master.dbo.sp_addlinkedserver @server = N'myserver\devdb_1',
@srvproduct=N'SQL Server'
END
ELSE
PRINT 'Link already exists'
但是,即使链接已经存在,OBJECT_ID测试也始终返回null.有什么方法可以在T-SQL中进行检查,以便我的其余代码可以假定链接始终存在?
But the OBJECT_ID test always returns null, even if the link already exists. Any way to do this check in T-SQL, so that the rest of my code can assume the link always exists?
推荐答案
签入 查看全文