SELECT
migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) cost_impact
,migs.avg_total_user_cost
,migs.avg_user_impact
,migs.user_seeks
,migs.user_scans
,mid.statement
,mid.equality_columns
,mid.inequality_columns
,mid.included_columns
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)
WHERE migs.group_handle in
(
SELECT TOP 50 group_handle
FROM sys.dm_db_missing_index_group_stats
ORDER BY avg_total_user_cost * avg_user_impact * (user_seeks + user_scans) DESC
)
ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESCselect
i.name as indes_name
, ob.name as table_name
, col.name as column_name
, ix.id
, ix.indid
, ix.keyno
from
sysindexkeys ix
, sysobjects ob
, syscolumns col
, sysindexes i
where
ix.id = ob.id
and ix.id = col.id
and ix.colid = col.colid
and i.id = ix.id
and i.indid = ix.indid
and ob.xtype in ('U','PK')
order by ob.name,ob.xtype,i.name,ix.id,ix.indid,ix.keyno
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Agent XPs', 1; GO RECONFIGURE GO
bcp database_name.dbo.table_name in filename.txt -Uuser -Ppass -Sserver -c