【问题标题】:Hierarchical List of All tables所有表的分层列表
【发布时间】:2011-04-21 08:42:16
【问题描述】:

在 SQL Server 数据库中,我必须找到所有“主”(父)表并构建一个 Paerent/Child 表的分层列表。最后我想遍历那个层次结构 从下列出并在最后删除所有子表数据,我可以删除 父数据也是。
我尝试过一种方法,即使用系统表(如 sys.objects 等)我 查询数据库的元数据(如其主键和外键)。但我不知道如何 制定树状结构。

【问题讨论】:

    标签: sql-server


    【解决方案1】:

    SQL Server Management Studio试试这个:

    EXEC sp_msdependencies @intrans = 1 
    

    如果您将结果插入到临时表中,则可以将其过滤为仅表、仅视图,或使用 proc 的其他替代参数来执行相同操作

    EXEC sp_msdependencies @intrans = 1 ,@objtype=8  --8 = tables
    EXEC sp_msdependencies @intrans = 1 ,@objtype=3  --3 = tables is the correct one
    

    查看更多Heirarchical

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 1970-01-01
      • 2010-10-29
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      相关资源
      最近更新 更多