Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12554

Primary Key as an included column

$
0
0

Hi all,

I have been using the missing index dmv as a guide for indexing opportunities.

One of the 'missing indexes' identified has listed primary key as an included column. As primary keys are always included in an index - is there any purpose for having a primary key as an included column?

Note, my primary key is on a single column - it is a surrogate key, bigint.

And here is the code i'm using to ID potential indexes:

SELECT mig.*, 
mid.statement AS table_name,
mid.equality_columns,
mid.inequality_columns,
mid.included_columns,
s.user_seeks * s.avg_total_user_cost * (s.avg_user_impact * 0.01) AS [index_rating], 
s.user_scans,
s.user_seeks,
s.avg_total_user_cost,
s.avg_user_impact
FROM sys.dm_db_missing_index_details AS mid WITH (NOLOCK)
INNER JOIN sys.dm_db_missing_index_groups AS mig WITH (NOLOCK)  ON mig.index_handle = mid.index_handle 
INNER JOIN sys.dm_db_missing_index_group_stats as s WITH (NOLOCK)  ON S.group_handle = mig.index_group_handle
ORDER BY 
index_rating desc

Thanks for reading.

Clay


Viewing all articles
Browse latest Browse all 12554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>