{"id":2622,"date":"2013-09-10T10:55:08","date_gmt":"2013-09-10T17:55:08","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/kimberly\/?p=2622"},"modified":"2020-12-11T10:44:08","modified_gmt":"2020-12-11T18:44:08","slug":"use-this-new-sql-server-2012-rewrite-for-sp_helpindex","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/use-this-new-sql-server-2012-rewrite-for-sp_helpindex\/","title":{"rendered":"(OLD): New SQL Server 2012 rewrite for sp_helpindex"},"content":{"rendered":"<p>Since I&#8217;ve rewritten sp_helpindex a few times, I have a few blogs posts in this category. Each time I do an update I&#8217;ll make the NEW version titled USE THIS.<\/p>\n<p>To use my version of sp_helpindex, you need TWO scripts. One script is version-specific and the other works on versions 2005, 2008\/R2 and 2012. All versions need this generic base procedure to produce the detailed output.<\/p>\n<h2>Step 1: Setup sp_SQLskills_ExposeColsInIndexLevels<\/h2>\n<p style=\"padding-left: 30px;\"><strong>Create this procedure first:<\/strong> <a href=\"https:\/\/www.sqlskills.com\/resources\/sp_helpindex\/sp_sqlskills_exposecolsinindexlevels.sql\">sp_SQLskills_ExposeColsInIndexLevels.sql<\/a> (7 kb).<\/p>\n<p style=\"padding-left: 30px;\">This is what gives us the tree\/leaf definitions. And, this works for all versions: 2005, 2008\/R2, and 2012.<\/p>\n<h2>Step 2: Setup the replacement procedure for sp_helpindex. This IS version specific:<\/h2>\n<p style=\"padding-left: 30px;\"><strong>On SQL Server 2005<\/strong>, use: <a href=\"https:\/\/www.sqlskills.com\/resources\/sp_helpindex\/sp_sqlskills_sql2005_helpindex.sql\">sp_SQLskills_SQL2005_helpindex.sql<\/a> (11 kb) to create sp_SQLskills_SQL2005_helpindex.<\/p>\n<p style=\"padding-left: 30px;\"><strong>On SQL Server 2008<\/strong>, use: <a href=\"https:\/\/www.sqlskills.com\/resources\/sp_helpindex\/sp_sqlskills_sql2008_helpindex.sql\">sp_SQLskills_SQL2008_helpindex.sql<\/a> (12 kb) to create sp_SQLskills_SQL2008_helpindex. (<strong>NOTE:<\/strong> This does run on SQL Server 2012 but if your table has a columnstore index, it will generate an error.)<\/p>\n<p style=\"padding-left: 30px;\"><strong>On SQL Server 2012<\/strong>, use: <a href=\"https:\/\/www.sqlskills.com\/resources\/sp_helpindex\/sp_sqlskills_sql2012_helpindex.sql\">sp_SQLskills_SQL2012_helpindex.sql<\/a> (12 kb) to create sp_SQLskills_SQL2012_helpindex.<\/p>\n<h2>Step 3: Setup a hot-key combination<\/h2>\n<p style=\"padding-left: 30px;\"><strong>Optionally<\/strong>, setup this procedure to be invoked through a keyboard shortcut using Tools, Options, Environment\/Keyboard. I usually make it Ctrl+F1 and I described how to do this <a href=\"https:\/\/www.sqlskills.com\/blogs\/kimberly\/a-new-and-improved-sp_helpindex-jokingly-sp_helpindex8\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<h2><\/h2>\n<h2>The Output<\/h2>\n<p>On SQL Server 2012, the output will look like the following (index_id 5 is a columnstore index):<\/p>\n<table border=\"0\" width=\"1703\" cellspacing=\"0\" cellpadding=\"0\">\n<colgroup>\n<col width=\"55\" \/>\n<col width=\"72\" \/>\n<col width=\"163\" \/>\n<col width=\"317\" \/>\n<col width=\"216\" \/>\n<col span=\"2\" width=\"141\" \/>\n<col width=\"158\" \/>\n<col width=\"440\" \/><\/colgroup>\n<tbody>\n<tr>\n<td width=\"55\" height=\"17\">index_id<\/td>\n<td width=\"72\">is_disabled<\/td>\n<td width=\"163\">index_name<\/td>\n<td width=\"317\">index_description<\/td>\n<td width=\"216\">index_keys<\/td>\n<td width=\"141\">included_columns<\/td>\n<td width=\"141\">filter_definition<\/td>\n<td width=\"158\">columns_in_tree<\/td>\n<td width=\"440\">columns_in_leaf<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"17\">1<\/td>\n<td align=\"right\">0<\/td>\n<td>[member_ident]<\/td>\n<td>clustered, unique, \u00a0 primary key located on PRIMARY<\/td>\n<td>[member_no]<\/td>\n<td>NULL<\/td>\n<td>NULL<\/td>\n<td>[member_no]<\/td>\n<td>All columns \u00a0 &#8220;included&#8221; &#8211; the leaf level IS the data row.<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"17\">2<\/td>\n<td align=\"right\">0<\/td>\n<td>[member_corporation_link]<\/td>\n<td>nonclustered located \u00a0 on PRIMARY<\/td>\n<td>[corp_no]<\/td>\n<td>NULL<\/td>\n<td>NULL<\/td>\n<td>[corp_no], \u00a0 [member_no]<\/td>\n<td>[corp_no], \u00a0 [member_no]<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"17\">3<\/td>\n<td align=\"right\">0<\/td>\n<td>[member_region_link]<\/td>\n<td>nonclustered located \u00a0 on PRIMARY<\/td>\n<td>[region_no]<\/td>\n<td>NULL<\/td>\n<td>NULL<\/td>\n<td>[region_no], \u00a0 [member_no]<\/td>\n<td>[region_no], \u00a0 [member_no]<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"17\">4<\/td>\n<td align=\"right\">0<\/td>\n<td>[LastNameInd]<\/td>\n<td>nonclustered located \u00a0 on PRIMARY<\/td>\n<td>[lastname]<\/td>\n<td>NULL<\/td>\n<td>NULL<\/td>\n<td>[lastname], \u00a0 [member_no]<\/td>\n<td>[lastname], \u00a0 [member_no]<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"17\">5<\/td>\n<td align=\"right\">0<\/td>\n<td>[columnstore_index]<\/td>\n<td>nonclustered \u00a0 columnstore located on PRIMARY<\/td>\n<td>n\/a, see \u00a0 columns_in_leaf for details<\/td>\n<td>n\/a, columnstore \u00a0 index<\/td>\n<td>n\/a, columnstore \u00a0 index<\/td>\n<td>n\/a, columnstore \u00a0 index<\/td>\n<td>Columns with \u00a0 column-based index: [member_no], [lastname], [firstname]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I hope this helps you when looking at your indexes!<\/p>\n<p>Enjoy,<br \/>\nkt<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since I&#8217;ve rewritten sp_helpindex a few times, I have a few blogs posts in this category. Each time I do an update I&#8217;ll make the NEW version titled USE THIS. To use my version of sp_helpindex, you need TWO scripts. One script is version-specific and the other works on versions 2005, 2008\/R2 and 2012. All [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,17,30,36,63],"tags":[],"class_list":["post-2622","post","type-post","status-publish","format-standard","hentry","category-clustered-index","category-clustering-key","category-filtered-indexes","category-indexes","category-sp_helpindex-rewrites"],"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/2622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/comments?post=2622"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/2622\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/media?parent=2622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/categories?post=2622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/tags?post=2622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}