我正试图找出一种方法来列出标记为要复制的所有活动数据库。
我尝试了两个不起作用的查询:
select * from [distribution].[dbo].[MSpublications]
在此代码中,您将看到已复制的所有数据库,即使此时尚未复制,但过去曾复制过。
select * from sys.databases
where is_published=1 or is_subscribed=1 or is_merge_published=1
我对第二个查询也不满意。
答案 0 :(得分:0)
我意识到你的帖子已经提交了很长一段时间,但由于没有提供合适的解决方案,我认为我会在下面提供所有内容,以防其他人遇到同样的情况。
<强>权限:强>
如果sys.databases的调用者不是数据库的所有者且数据库不是master或tempdb,则查看相应行所需的最小权限是ALTER ANY DATABASE或VIEW ANY DATABASE服务器级权限,或CREATE DATABASE权限。主数据库。始终可以在sys.databases中查看呼叫者所连接的数据库 (MSDN: permissions required to view sys.databases)
DECLARE @db NVARCHAR(70);
SET @db = N'{database_name}'; --Insert here the name of the DB-in-question.
SELECT @db AS [Database],
CASE DATABASEPROPERTYEX(@db, N'IsPublished') WHEN 1 THEN N'TRUE' ELSE 'FALSE' END AS [Published],
CASE DATABASEPROPERTYEX(@db, N'IsSubscribed') WHEN 1 THEN N'TRUE' ELSE 'FALSE' END AS [Subscribed],
CASE DATABASEPROPERTYEX(@db, N'IsMergePublished') WHEN 1 THEN N'TRUE' ELSE 'FALSE' END AS [Merge_Published];
DECLARE @sql NVARCHAR(1000);
SET @sql = N'USE ?;
SELECT ''?'' AS [Database],
CASE DATABASEPROPERTYEX(''?'', N''IsPublished'') WHEN 1 THEN N''TRUE'' ELSE ''--'' END AS [Published],
CASE DATABASEPROPERTYEX(''?'', N''IsSubscribed'') WHEN 1 THEN N''TRUE'' ELSE ''--'' END AS [Subscribed],
CASE DATABASEPROPERTYEX(''?'', N''IsMergePublished'') WHEN 1 THEN N''TRUE'' ELSE ''--'' END AS [Merge_Published];';
EXEC sp_msForEachDB @SQL;
DECLARE @sql NVARCHAR(1000);
DECLARE @tbl AS TABLE (
[db] NVARCHAR(70),
[isPublished] NVARCHAR(5),
[isSubscribed] NVARCHAR(5),
[isMergePublished] NVARCHAR(5));
SET @sql =
N'IF ''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''distribution'') BEGIN
USE ?;
SELECT ''?'' AS [Database],
CASE DATABASEPROPERTYEX(''?'', N''IsPublished'') WHEN 1 THEN N''TRUE'' ELSE ''--'' END AS [Published],
CASE DATABASEPROPERTYEX(''?'', N''IsSubscribed'') WHEN 1 THEN N''TRUE'' ELSE ''--'' END AS [Subscribed],
CASE DATABASEPROPERTYEX(''?'', N''IsMergePublished'') WHEN 1 THEN N''TRUE'' ELSE ''--'' END AS [Merge_Published];
END';
INSERT INTO @tbl EXEC sp_msForEachDB @SQL;
SELECT * FROM @tbl ORDER BY [db] ASC;
答案 1 :(得分:-2)
exec sp_helpreplicationdboption