SQL语句实现查询并自动创建Missing Index

SELECT

 migs.avg_total_user_cost*(migs.avg_user_impact/ 100.0) *(migs.user_seeks + migs.user_scans) ASimprovement_measure,

 'CREATE INDEX[missing_index_' + CONVERT(varchar, mig.index_group_handle) + '_' + CONVERT(varchar, mid.index_handle)

 + '_' + LEFT(PARSENAME(mid.statement, 1), 32) + ']'

 + ' ON ' + mid.statement

 + ' (' + ISNULL(mid.equality_columns,'')

  + CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columnsIS NOT NULL THEN ',' ELSE '' END

  + ISNULL(mid.inequality_columns, '')

 + ')'

 + ISNULL(' INCLUDE (' + mid.included_columns+ ')', '') AScreate_index_statement,

 migs.*, mid.database_id, mid.[object_id]

FROM sys.dm_db_missing_index_groups mig

INNER JOIN sys.dm_db_missing_index_group_statsmigs ON migs.group_handle= mig.index_group_handle

INNER JOIN sys.dm_db_missing_index_detailsmid ON mig.index_handle= mid.index_handle

WHERE migs.avg_total_user_cost *(migs.avg_user_impact /100.0) *(migs.user_seeks + migs.user_scans) > 10

ORDER BY migs.avg_total_user_cost* migs.avg_user_impact*(migs.user_seeks + migs.user_scans) DESC
(0)

相关推荐

  • SQL语句实现查询并自动创建Missing Index

    SELECT migs.avg_total_user_cost*(migs.avg_user_impact/ 100.0) *(migs.user_seeks + migs.user_scans) ASimprovement_measure, 'CREATE INDEX[missing_index_' + CONVERT(varchar, mig.index_group_handle) + '_' + CONVERT(varchar, mid.index_handle) + '_' + LEFT

  • java执行SQL语句实现查询的通用方法详解

    完成SQL查询 并将查询结果放入Vector容器,以便其他程序使用 /* * 执行sql查询语句 */ public static <T> Vector<T> executeQuery(Class<T> clazz, String sql, Object... args) { Connection conn = null; PreparedStatement preparedstatement = null; ResultSet rs = null; Vector<

  • PHP获取MySQL执行sql语句的查询时间方法

    如下所示: //计时开始 runtime(); //执行查询 mysql_query($sql); //计时结束. echo runtime(1); //计时函数 function runtime($mode=0) { static $t; if(!$mode) { $t = microtime(); return; } $t1 = microtime(); list($m0,$s0) = explode(" ",$t); list($m1,$s1) = explode("

  • 使用SQL语句实现查询排序,顺序和倒序

    目录 SQL语句查询排序,顺序和倒序 SQL查询结果排序 SQL语句查询排序,顺序和倒序 SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC, OrderNumber ASC #ASC升序,DESC倒序 SQL查询结果排序 1.以指定顺序返回查询结果(order by的asc为升序,desc为降序) select ename,job,sal from emp where deptno = 10 order by sal as

  • vb.net 数组参与SQL语句的查询范例

    首先定义数组,我是同事session传值的 复制代码 代码如下: Dim struser As New List(Of String)struser = Session("chooseuser")strruser = "" For a = 0 To struser.Count - 1If a = 0 Thenstrruser = "'" & struser.Item(a).ToString.Trim & "'"

  • SQL语句实现查询SQL Server内存使用状况

    SELECT type,--Clerk的类型 sum(virtual_memory_reserved_kb)as vm_Reserved_kb,--保留的内存 sum(virtual_memory_committed_kb)as vm_Committed_kb,--提交的内存 sum(awe_allocated_kb)as awe_Allocated_kb,--开启AWE后使用的内存 sum(shared_memory_reserved_kb)as sm_Reserved_kb,--共享的保留内

  • SQL语句实现查询SQL Server服务器名称和IP地址

    获取服务器名称: SELECT SERVERPROPERTY('MachineName') select @@SERVERNAME select HOST_NAME() 获取IP地址可以使用xp_cmdshell执行ipconfig命令: --开启xp_cmdshell exec sp_configure'show advanced options', 1 reconfigure with override exec sp_configure'xp_cmdshell', 1 reconfigur

  • SQL语句实现查询当前数据库IO等待状况

    sys.dm_io_pending_io_requests可以返回当前IO Pending的状态,对于SQL Server 中每个挂起的I/O 请求,返回与其对应的一行,跟sys.dm_io_virtual_file_stats配合可以看到具体是哪个数据库IO出现问题. select DB_NAME(database_id) as DBNAME, database_id, file_id, io_stall, io_pending_ms_ticks, scheduler_address from

  • SQL语句实现查询Index使用状况

    SELECT sch.name + '.' + t.name AS [Table Name], i.name AS[Index Name], i.type_desc, ISNULL(user_updates,0) AS [Total Writes], ISNULL(user_seeks +user_scans + user_lookups,0) AS [Total Reads], s.last_user_seek, s.last_user_scan , s.last_user_lookup, I

  • 查找MySQL中查询慢的SQL语句方法

    如何在mysql查找效率慢的SQL语句呢?这可能是困然很多人的一个问题,MySQL通过慢查询日志定位那些执行效率较低的SQL 语句,用--log-slow-queries[=file_name]选项启动时,mysqld 会写一个包含所有执行时间超过long_query_time 秒的SQL语句的日志文件,通过查看这个日志文件定位效率较低的SQL .下面介绍MySQL中如何查询慢的SQL语句 一.MySQL数据库有几个配置选项可以帮助我们及时捕获低效SQL语句 1,slow_query_log 这

随机推荐