INDEX--索引相关信息查看
--==============================================
--查看可能缺失的索引
SELECT
mig.*
,migs.*
,mid.*
FROM sys.dm_db_missing_index_group_stats AS migs
INNER JOIN sys.dm_db_missing_index_groups AS mig
ON (migs.group_handle = mig.index_group_handle)
INNER JOIN sys.dm_db_missing_index_details AS mid
ON (mig.index_handle = mid.index_handle)
--查看索引碎片
--'DETAILED'选项会导致扫描全表,慎用
SELECT OBJECT_NAME (ips.[object_id]) AS 'Object Name',
si.name AS 'Index Name',
ROUND (ips.avg_fragmentation_in_percent, 2) AS 'Fragmentation',
ips.page_count AS 'Pages',
ROUND (ips.avg_page_space_used_in_percent, 2) AS 'Page Density'
FROM sys.dm_db_index_physical_stats (DB_ID ('SQLskillsDB'), NULL, NULL, NULL, 'DETAILED')
ips CROSS APPLY sys.indexes si
WHERE si.object_id = ips.object_id
AND si.index_id = ips.index_id
AND ips.index_level = 0 -- only the leaf level
AND ips.avg_fragmentation_in_percent > 10; -- filter on fragmentation
GO
--===============================================
--查看索引结构
;WITH T1
AS (
SELECT IC.* ,
C.name AS ColumnName
FROM sys.index_columns IC
INNER JOIN sys.columns C
ON IC.object_id = C.object_id
AND IC.column_id = C.column_id
)
SELECT
--DB_ID() AS DatabaseID,
DB_NAME() AS DatabaseName ,
SCHEMA_NAME(TB.schema_id) AS SchemaName ,
TB.name AS TableName ,
--IX.index_id AS IndexId,
ISNULL(IX.name, '') AS IndexName ,
IX.type_desc AS IndexType ,
ISNULL(IXK.ix_index_column_name, '') AS IndexKey ,
ISNULL(IXK.ix_index_include_column_name, '') AS IndexIncludeColumn ,
ISNULL(IX.filter_definition, '') AS FilerDefinition ,
IX.is_primary_key AS IsPrimaryKey ,
IX.is_unique AS IsUnique ,
IX.is_disabled AS IsDisabled ,
IX.fill_factor AS FileFactor ,
IX.has_filter AS HasFiler ,
IX.ignore_dup_key AS IgnoreDuplicateKey ,
DS.name AS DataSpace ,
ISNULL(PS.name, '') AS PartitionScheme ,
ISNULL(IXC.ColumnName, '') AS PartitionKey ,
IX.allow_page_locks AS AllowPageLocks ,
IX.allow_row_locks AS AllowRowLocks ,
IX.is_padded AS IsPadded
FROM sys.tables TB
INNER JOIN sys.indexes IX
ON TB.object_id = IX.object_id
INNER JOIN sys.data_spaces DS
ON DS.data_space_id = IX.data_space_id
LEFT JOIN sys.partition_schemes PS
ON IX.data_space_id = PS.data_space_id
LEFT JOIN T1 AS IXC ON IX.object_id = IXC.object_id
AND IX.index_id = IXC.index_id
AND IXC.partition_ordinal = 1
OUTER APPLY (
SELECT ix_index_column_name =
STUFF(REPLACE(REPLACE((
SELECT CASE WHEN T1.is_descending_key = 1
THEN T1.ColumnName+ ' desc'
ELSE T1.ColumnName
END AS column_name
FROM T1
WHERE IX.object_id = T1.object_id
AND IX.index_id = T1.index_id
AND T1.is_included_column = 0
ORDER BY index_column_id
FOR XML AUTO),'<T1 column_name="',','), '"/>', ''),1, 1, '') ,
ix_index_include_column_name =
STUFF(REPLACE(REPLACE(( SELECT
T1.ColumnName AS column_name
FROM T1
WHERE IX.object_id = T1.object_id
AND IX.index_id = T1.index_id
AND T1.is_included_column = 1
ORDER BY index_column_id
FOR XML AUTO),'<T1 column_name="',','), '"/>', ''),1, 1, '')
) AS IXK
--WHERE TB.name='t_coupon'
ORDER BY TableName,IndexKey,IndexIncludeColumn
--==========================================
--查看索引的使用情况
--索引在重建或删除新建时sys.dm_db_index_usage_stats中相关的数据会被清除
--索引在重整是不会清除sys.dm_db_index_usage_stats的数据
SELECT
DB_NAME(ixu.database_id) DataBase_Name,
OBJECT_NAME(ixu.object_id) Table_Name,
ix.name Index_Name ,
(
SELECT MAX(s.rows)
FROM sysindexes s
WHERE s.id = ixu.object_id
) AS Table_Rows ,
STATS_DATE(ixu.object_id, ixu.index_id) AS statistic_time,
ixu.user_updates,
ixu.last_user_seek,
ixu.user_seeks,
ixu.last_user_scan,
ixu.user_scans,
ixu.last_user_lookup,
ixu.user_lookups,
ixu.user_updates/(ISNULL(ixu.user_seeks,0)
+ISNULL(ixu.user_scans,0)+1) AS UseRate
FROM sys.dm_db_index_usage_stats ixu
INNER JOIN sys.indexes ix
ON ixu.object_id = ix.object_id
AND ixu.index_id = ix.index_id
INNER JOIN sys.objects ob
ON ixu.object_id = ob.object_id
WHERE ob.type = 'U'
AND ob.is_ms_shipped = 0
AND ixu.database_id=DB_ID()
--AND ix.object_id=OBJECT_ID('TableName')
INDEX--索引相关信息查看的更多相关文章
- inodes 相关信息查看
查看inode数量 df -ih 查看磁盘信息 tune2fs -l /dev/sdc1 查看相关目录信息 /data/osd.3/bean_test/7/8/9# debugfs /dev/sdc2 ...
- linux服务器的相关信息查看(端口占用,cpu、内存占用,防火墙,系统信息,vim编辑器使用等)
一.端口占用情况 https://www.cnblogs.com/CEO-H/p/7794306.html (1)查看所有端口.进程的使用情况:netstat -tunlp (2)查看某一端口的使 ...
- SQL存储过程相关信息查看转
原文地址:http://www.cnblogs.com/minideas/archive/2009/10/29/1591891.html --1.查看所有存储过程与函数 exec sp_ ...
- Linux CPU相关信息查看
linux 下查看机器是cpu是几核的 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu ...
- SQL存储过程相关信息查看
--1.查看所有存储过程与函数 exec sp_stored_procedures 或者 select * from dbo.sysobjects where OBJECT ...
- cpu相关信息查看
查看CPU型号:grep "model name" /proc/cpuinfo | uniqdmidecode -s processor-version | uniq 查看物理CP ...
- MySQL查看数据库相关信息
使用MySQL时,需要了解当前数据库的情况,例如当前的数据库大小.字符集.用户等等.下面总结了一些查看数据库相关信息的命令 1:查看显示所有数据库 mysql> show databases ...
- [转]MySQL查看数据库相关信息
原文链接:MySQL查看数据库相关信息 使用MySQL时,需要了解当前数据库的情况,例如当前的数据库大小.字符集.用户等等.下面总结了一些查看数据库相关信息的命令 1:查看显示所有数据库 mysql& ...
- 关于MySQL相关的查看显示信息:
关于MySQL相关的查看显示信息: 数据库范围: 一.查看所有的数据库:(仅仅是看数据库数量与名字) mysql> show databases; 二.查看某个数据库的创建信息:(主要看数据库的 ...
随机推荐
- 【airflow实战系列】 基于 python 的调度和监控工作流的平台
简介 airflow 是一个使用python语言编写的data pipeline调度和监控工作流的平台.Airflow被Airbnb内部用来创建.监控和调整数据管道.任何工作流都可以在这个使用Pyth ...
- ZooKeeper架构
ZooKeeper服务器端运行于两种模式下:独立模式(standalone)和仲裁模式(quorum).独立模式几乎与其术语所描述的一样:有一个单独的服务器,ZooKeeper状态无法复制.在仲裁模式 ...
- rtmp聊天相关归总
使用共享对象(SharedObject)来开发时时文字聊天其实是很简单的. SharedObject可以跟踪和广播消息,连接到SharedObject中的其中任何一个客户端改变了SharedObjec ...
- Elasticsearch 搜索引擎
简介: Elasticsearch 是一个实时的分布式搜索和分析引擎.它可以帮助你用前所未有的速度去处理大规模数据.它可以用于全文搜索,结构化搜索以及分析. 分布式实时文件存储,并将每一个字段都 ...
- Core Data 入门
1. 基本概念 Core Data是一种被称为对象关系映射(Object-Relational Mapping,ORM)技术的实现. Core Data 架构图如下: 五个概念: (1)数据模型(Da ...
- jenkins-为什么要持续集成
持续集成(Continuous Integration),也就是我们经常说的 CI,是现代软件开发技术的基础.本文论述了当前软件开发过程中存在的问题,讲解了持续集成.持续集成服务器的概念,最终探讨了为 ...
- 如何显示当前Mipmap级别?
[如何显示当前Mipmap级别?] 乘以 mainTextureSize/mipTextureSize是为了让mipColorsTexture纹理与mainTexture级别对应.直接用uv是不行的, ...
- RedHat Linux设置yum软件源为本地ISO
先挂载ISO到某个目录下(如我的:/media/RHEL_6.0 x86_64 Disc 1) # mount –o loop rhel-server-6.4-x86_64-dvd.iso /medi ...
- c++之带默认形参值的函数
先来个例子: #include <iostream> using namespace std; ,){ return x+y; } int main(){ //freopen(" ...
- java动态规划取硬币问题
最近一直在研究动态规划的问题.今天遇到了取硬币问题. 其实动态规划还是,我从底部向顶部,依次求出每个状态的最小值,然后就可以标记上. 这道题目就是,假如有1,5,7,10这四种币值的硬币,我取14元, ...