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

发布于 2024-07-26 00:41:23 字数 59 浏览 3 评论 0原文

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

I was asked to do this, but I don't know if there is a standard way of doing so. Does anyone know if there is a way in SQL Server to export this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南七夏 2024-08-02 00:41:24

据我所知,没有标准方法可以做到这一点。 复制作为一种早在 XML 之前就存在的技术,其工具集和元数据并不是以 XML 为中心的。 但是,与复制相关的所有内容都存储在表中的某个位置,无论是在 master 中还是在 msdb 中或在分发数据库中,请参阅 MSDN 上的复制表主题 或复制 DMV 中 (sys.dm_repl_articlessys.dm_repl_schemas)。 所有这些信息都可以查询并格式化为 XML,但我不知道有任何标准 XML 模式涵盖了这些信息。

AFIK there is no standard way of doing this. Replication as a technology long predates XML and its toolset and metadata is not XML centric. However everything related to replication is stored somewhere in a table, either in master or in msdb or in distribution database, see Replication Tables topic on MSDN, or in the replication DMVs (sys.dm_repl_articles and sys.dm_repl_schemas). All this information can be interogated and formatted as XML, but I'm not aware of any standard XML schemas covering this information.

蔚蓝源自深海 2024-08-02 00:41:24

莱姆斯的回答非常有效。 这是我用来将其导出为 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

Remus' answer worked great. Here is the SQL script I used to export this to XML. Hopefully it will be useful to someone else:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文