zoukankan      html  css  js  c++  java
  • SQL NOTEDMV For Index

    --查看用户查询使用索引情况
    SELECT 
    DB_NAME() AS DatabaseName 
    ,SCHEMA_NAME(o.Schema_ID) AS SchemaName 
    ,OBJECT_NAME(s.[object_id]) AS TableName 
    ,i.name AS IndexName 
    ,s.user_updates
    ,s.user_scans
    ,s.user_seeks
    ,s.user_lookups
    ,s.system_seeks + s.system_scans + s.system_lookups AS SystemUsage
    FROM sys.dm_db_index_usage_stats s 
    INNER JOIN sys.indexes i 
    ON s.[object_id] = i.[object_id] 
    AND s.index_id = i.index_id 
    INNER JOIN sys.objects o 
    ON i.object_id = O.object_id
    ORDER BY S.user_updates DESC
    --查看索引碎片情况
    SELECT
    DB_NAME() AS DatbaseName 
    ,SCHEMA_NAME(o.Schema_ID) AS SchemaName 
    ,OBJECT_NAME(s.[object_id]) AS TableName 
    ,i.name AS IndexName 
    ,s.avg_fragmentation_in_percent
    ,s.index_depth
    FROM sys.dm_db_index_physical_stats(db_id(),null, null, null, null) s 
    INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] 
    AND s.index_id = i.index_id 
    INNER JOIN sys.objects o ON i.object_id = O.object_id
    WHERE i.name IS NOT NULL 
    AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0 
    ORDER BY s.avg_page_space_used_in_percent DESC
    --查看索引统计的相关信息
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
    SELECT 
    ss.name AS SchemaName 
    ,st.name AS TableName 
    ,s.name AS IndexName 
    ,STATS_DATE(s.id,s.indid) AS 'Statistics Last Updated' 
    ,s.rowcnt AS 'Row Count' 
    ,s.rowmodctr AS 'Number Of Changes' 
    ,CAST((CAST(s.rowmodctr AS DECIMAL(28,8))/CAST(s.rowcnt AS DECIMAL(28,2)) * 100.0) AS DECIMAL(28,2)) AS '% Rows Changed' 
    FROM sys.sysindexes s 
    INNER JOIN sys.tables st ON st.[object_id] = s.[id] 
    INNER JOIN sys.schemas ss ON ss.[schema_id] = st.[schema_id] 
    WHERE s.id > 100 
    AND s.indid > 0 
    AND s.rowcnt >= 500 
    ORDER BY SchemaName, TableName, IndexName 
  • 相关阅读:
    一生要做的99件事
    Flash 简单的Mouse.hide()
    [转]FCKeditor
    [转]pv是什么意思?什么是pv值,pv访问量?网站pv是什么?
    CSS:用DIV+CSS实现表格形式的数据排列
    css "Float"
    Jemin的div+css测试文件
    原来
    我终于知道什么情况下得用table了
    转的 关于div 的重叠
  • 原文地址:https://www.cnblogs.com/TeyGao/p/2737640.html
Copyright © 2011-2022 走看看