zoukankan      html  css  js  c++  java
  • 如何查询SQL Server 中 Index 的创建时间

    今天有人问如何查询index的创建时间,使用下面的脚本可以查询出索引列已经创建时间,但是这个脚本只是针对,Pimary Key,Unique Index,其他 nonclustered index 是查询不到创建时间的,根本没有保存:

    select
        i.name as IndexName,
        o.name as TableName,
        ic.key_ordinal as ColumnOrder,
        ic.is_included_column as IsIncluded,
        co.[name] as ColumnName,
        o.create_date
    from sys.indexes i
    join sys.objects o on i.object_id = o.object_id
    join sys.index_columns ic on ic.object_id = i.object_id
        and ic.index_id = i.index_id
    join sys.columns co on co.object_id = i.object_id
        and co.column_id = ic.column_id
    where i.name like '%IX_tablename_column%'   -- input index name
    --and i.[type] = 2
    --and i.is_unique = 0
    --and i.is_primary_key = 0
    --and o.[type] = 'U'
    --and ic.is_included_column = 0
    order by o.[name], i.[name], ic.is_included_column, ic.key_ordinal;

    如果需要查询索引最后一次更新的时间,使用下面的脚本:

    SELECT object_schema_name(stats.object_id) AS Object_Schema_Name,
        object_name(stats.object_id) AS Object_Name,
        indexes.name AS Index_Name,
        STATS_DATE(stats.object_id, stats.stats_id) AS Stats_Last_Update  --这是从统计信息里确定更新的时间
    FROM sys.stats
    JOIN sys.indexes
        ON stats.object_id = indexes.object_id
        AND stats.name = indexes.name
    where indexes.name like '%IX_tablename_column%'

  • 相关阅读:
    Pyinstaller(python打包为exe文件)
    matplotlib 填充颜色
    Visual Studio 2015 Enterprise
    latex中pdflatex与xelatex的区别
    latex插图续
    dva+umi+antd项目从搭建到使用(没有剖验证,不知道在说i什么)
    umi+dva+antd新建项目(亲测可用)
    HTTP缓存机制
    企业网站常见需求整理
    立足于运维与监控的前端框架 NoahV
  • 原文地址:https://www.cnblogs.com/yuzg/p/10861723.html
Copyright © 2011-2022 走看看