什么是在SQL 2000、2005和2008兼容格式中检查复制是否已启用的最简单方法?不需要任何状态信息,只需知道DB是否已启用。我需要这个信息,因为我希望我的数据库迁移代码在尝试执行模式更新之前,如果启用了复制,则会抛出异常。
谢谢。
谢谢。
我找到了这个查询,但它仅适用于SQL 2005及更高版本(不适用于SQL 2000版本)。
T-SQL查询
select name, is_published, is_subscribed, is_merge_published, is_distributor
from sys.databases
where is_published = 1 or is_subscribed = 1 or
is_merge_published = 1 or is_distributor = 1
SELECT COUNT(*) AS IsPublished
FROM sys.databases
WHERE (is_published | is_subscribed | is_merge_published) AND (name = @dbname)
SELECT name
FROM sys.databases
WHERE (is_published | is_subscribed | is_merge_published | is_distributor = 1)
-- ================================================
-- Author: J. Duke Rogers
-- Communicore Technologies &
-- Triangle Forensics
-- Create date: 07.25.20
-- Description: If @dbname is null or '' it uses
-- the database in which it is defined
-- WARNING: May cause black hole(s)
-- ================================================
CREATE FUNCTION fn_IsReplicationEnabled
(
@dbname sysname =NULL
)
RETURNS bit
AS
BEGIN
DECLARE @Result int
IF (@dbname is null or @dbname='')
set @dbname=DB_NAME()
SELECT @Result=COUNT(*)
FROM
sys.databases
WHERE
is_published | is_subscribed | is_merge_published=1 AND [name] = @dbname
IF @Result is null or @Result <0 or @Result>1
return CAST('Something impossible has occurred, singularity and/or black hole
imminent, don helmet!' as bit)
RETURN IIF(@Result=1,1,0)
END
GO
IMHO
来自: www.mssqlinsider.com/2013/09/check-databases-part-replication:
SELECT
name as [Database name],
CASE is_published
WHEN 0 THEN 'No'
ELSE 'Yes'
END AS [Is Published],
CASE is_merge_published
WHEN 0 THEN 'No'
ELSE 'Yes'
END AS [Is Merge Published],
CASE is_distributor
WHEN 0 THEN 'No'
ELSE 'Yes'
END AS [Is Distributor],
CASE is_subscribed
WHEN 0 THEN 'No'
ELSE 'Yes'
END AS [Is Subscribed]
FROM sys.databases
WHERE database_id > 4