2009-06-30 76 views
0

我被要求这样做,但我不知道是否有这样做的标准方式。有谁知道是否有方法在SQL Server中导出?是否可以将我的SQL复制定义导出到XML?

+0

您能否定义您的定义是什么意思?例如,你的意思是你的SQL Server复制配置的细节? – 2009-06-30 20:40:00

回答

1

AFIK没有这样做的标准方法。作为技术的复制早于XML,其工具集和元数据不是以XML为中心的。但是,与复制相关的所有内容都存储在表的某处,无论是在主数据库还是在msdb或分发数据库中,请参见Replication Tables topic on MSDN或复制DMV(sys.dm_repl_articlessys.dm_repl_schemas)。所有这些信息都可以用XML格式化和格式化,但我不知道覆盖这些信息的任何标准XML模式。

0

Remus的回答非常好。这是我用来将它导出到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