【问题标题】:TSQL: Check if distributor exists before executing sp_dropdistributorTSQL:在执行 sp_dropdistributor 之前检查分发服务器是否存在
【发布时间】:2017-05-29 20:34:49
【问题描述】:

有没有办法在 T-SQL 中使用此命令删除分发服务器之前检查分发服务器是否存在?

exec sp_dropdistributor @no_checks = 1, @ignore_distributor=1

类似这样的:

If (Distributor Exists) Then 
   exec sp_dropdistributor @no_checks = 1, @ignore_distributor=1

我正在尝试避免在执行该语句并且分发器不存在时生成的此错误:

消息 21043,级别 16,状态 1,过程 sp_dropdistributor,第 50 行
分发器未安装。

【问题讨论】:

标签: c# .net sql-server tsql


【解决方案1】:

您可以使用sp_get_distributor 过程:

    declare @temp table
    (
        is_installed int,
        distribution_server_name varchar(500),
        is_distribution_db_installed int,
        is_distribution_publisher int,
        has_remote_distribution_publisher int
    );

    insert @temp exec sp_get_distributor

    if((select is_installed from @temp) = 1)
    begin
      exec sp_dropdistributor @no_checks = 1, @ignore_distributor=1
    end

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2022-11-25
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多