zoukankan      html  css  js  c++  java
  • SQL Server 2012 查询数据库中所有表的索引信息

    查询语句如下:

    with temp as(
        select  a.name as tabname,a.object_id
        ,h.name as indexName,h.index_id,ic.column_id,c.name colName
        from  sys.objects    as  a
        right join sys.indexes  as h  on  a.object_id=h.object_id
        left join sys.index_columns ic on h.index_id=ic.index_id and ic.object_id=a.object_id
        left join sys.columns c on ic.column_id=c.column_id and c.object_id=a.object_id
        where  a.type<>'s' and a.type='U'
        --and isnull(h.name,'')='' --没有索引的表
        and a.is_ms_shipped<>1 --排除 dtproperties
    )
     
    select distinct temp.tabname,indexName
    ,stuff((
            select ',' + tc.name from sys.columns tc
            left join sys.index_columns ic on ic.column_id=tc.column_id and ic.object_id=temp.object_id
            where tc.object_id=temp.object_id and ic.index_id=temp.index_id and tc.column_id in (
                select column_id from temp where object_id=tc.object_id and ic.index_id=temp.index_id
                ) for xml path('')
        ),1,1,''
    ) columnName
    from temp
    order by temp.indexName
    
  • 相关阅读:
    如何找bug
    信号量
    带组装的测试
    Oracle的一些操作
    NPOI的操作
    初次认识 C# win32 api
    C# 通过Selecnuim WebDriver操作非IE浏览器
    DevExpress.chartControt画趋势图
    DevExpress.chartContro控件保存图片和打印图片
    SqlServer基础复习
  • 原文地址:https://www.cnblogs.com/ruishine/p/14634339.html
Copyright © 2011-2022 走看看