查詢SQL SERVER 缺少INDEX的命令
-- 查詢缺少INDEX的命令 SELECT DatabaseName = DB_NAME(database_id) ,[Number Indexes Missing] = count(*) FROM sys.dm_db_missing_index_details GROUP BY DB_NAME(database_id) ORDER BY 2 DESC; -- 查詢缺少INDEX的項目 SELECT TOP 10 [Total Cost] = ROUND(avg_total_user_cost * avg_user_impact * (user_seeks + user_scans),0) , avg_user_impact , TableName = statement , [EqualityUsage] = equality_columns , [InequalityUsage] = inequality_columns , [Include Cloumns] = included_columns FROM sys.dm_db_missing_index_groups g INNER JOIN sys.dm_db_missing_index_group_stats s ON s.group_handle = g.index_group_handle INNER JOIN sys.dm_db_missing_index_details d ON d.index_handle = g.index_handle ORDER BY [Total Cost] DESC; 查出缺少的INDEX建議後,用下面的命令建立INCLUDE( 涵蓋索引 ) create index idx3 on Person.Person(MiddleName,EmailPromotion) include (FirstName,LastName,Title,PersonType) equality_columns用法 CREATE NONCLUSTERED INDEX IX_dbo_My_Table__Float_Filtered ON dbo . My_Table ( my_Float_column )