是否可以将我的SQL复制定义导出到XML?

时间:2009-06-30 20:11:46

标签: sql-server xml replication

我被要求这样做,但我不知道是否有这样做的标准方法。有谁知道SQL Server中是否有一种方法可以导出它?

2 个答案:

答案 0 :(得分:1)

AFIK没有标准的做法。复制作为一种技术早于XML,其工具集和元数据不是以XML为中心的。但是,与复制相关的所有内容都存储在表中的某个位置,可以是master,也可以是msdb或分发数据库,​​请参阅Replication Tables topic on MSDN或复制DMV(sys.dm_repl_articlessys.dm_repl_schemas)。所有这些信息都可以插入并格式化为XML,但我不知道有任何标准的XML模式来涵盖这些信息。

答案 1 :(得分:0)

雷姆斯的回答非常有效。这是我用来将其导出到XML的SQL脚本。希望它对其他人有用:

DECLARE @PublicationId INT
SET @PublicationId = 1 –- Use your publication ID here. Use SELECT * FROM syspublications to see a list of publications

select
      Publication.name AS [Name]
      , Publication.description AS [Description]
      , Article.name AS [Name]
      , Article.dest_table AS [Table]
      , [Column].name AS [Name]
      , [Column].[Type]
      , [Column].MaxLength
      , [Column].Nullable
from dbo.syspublications Publication
      join dbo.sysarticles Article on Publication.pubid = Article.pubid
            join sys.tables st on st.object_id = Article.objid
      join dbo.sysarticlecolumns ac on Article.artid = ac.artid
      join 
      (
            select
                  sc.object_id
                  , sc.column_id
                  , sc.name AS [Name]
                  , sty.name AS [Type]
                  , sc.max_length AS MaxLength
                  , sc.is_nullable AS Nullable
            from dbo.syspublications p
                  join dbo.sysarticles a on p.pubid = a.pubid
                  join dbo.sysarticlecolumns ac on a.artid = ac.artid
                        join sys.columns sc on sc.object_id = a.objid AND sc.column_id = ac.colid
                  join sys.types sty on sty.user_type_id = sc.user_type_id
            where p.pubid = @PublicationId
      ) [Column] on [Column].object_id = Article.objid AND [Column].column_id = ac.colid
where Publication.pubid = @PublicationId FOR XML AUTO