{"id":4618,"date":"2013-02-21T17:24:15","date_gmt":"2013-02-21T17:24:15","guid":{"rendered":"http:\/\/craftydba.com\/?p=4618"},"modified":"2013-02-21T19:05:57","modified_gmt":"2013-02-21T19:05:57","slug":"managing-indexes-with-ssms","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=4618","title":{"rendered":"Managing Indexes with SSMS"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/key_primary_icon.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/key_primary_icon.jpg\" alt=\"\" title=\"key_primary_icon\" width=\"128\" height=\"128\" class=\"alignleft size-full wp-image-4620\" \/><\/a>Most of the articles that I presented so far for database development have been centered around the exact Microsoft T-SQL syntax to perform a certain operation.  At the <a href=\"http:\/\/www.cs.uri.edu\/\">University of Rhode Island<\/a>, I learnt how to program in Pascal before typing in my first ANSI SQL statement.  In short, I will always be some type of developer in my heart.  <\/p>\n<p>However, many people do not come from a computer science and math background.  The SQL Server Management Studio (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb934498.aspx\">SSMS<\/a>) has menus and dialog boxes to achieve many of the same results.  <\/p>\n<p>Today, I am going to continue the series of articles that will recreate the [AUTOS] sample database while demonstrating how common T-SQL tasks in my <a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/designing-with-ssms.sql_.txt\">script<\/a> can be done with SSMS.  <\/p>\n<p>I want to explore how to <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188783.aspx\">CREATE INDEX<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms176118.aspx\">DROP INDEX<\/a>, and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188388.aspx\">ALTER INDEX<\/a> commands be duplicated using the SSMS graphical interface.  Please see section 1I in the code for defining indexes.<\/p>\n<p>My example will assume that the [ACTIVE].[MAKES] table has been created without any indexes.  <\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-0.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-0.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-NEW-INDEX-0\" width=\"506\" height=\"472\" class=\"aligncenter size-full wp-image-4625\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-0.jpg 506w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-0-300x279.jpg 300w\" sizes=\"auto, (max-width: 506px) 100vw, 506px\" \/><\/a><\/p>\n<p>Let&#8217;s explore some of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188783.aspx\">CREATE INDEX<\/a> graphical windows.<\/p>\n<p>Find the indexes node for the table in SSMS and right click to bring up the sub-menu.  Select the new index option.  This action will bring up the table designer in the background and the new index dialog box in the foreground.  <\/p>\n<p>First, we are going to work on creating the <span style=\"color: #FF0000;\">unique index<\/span>.  Type [UNQ_MAKER_NM] as the index name, check the unique index box and make sure the index key column is [MAKER_NM].  Clicking the OKAY button will add the index and the CANCEL button will abort the action.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-NEW-INDEX-1\" width=\"865\" height=\"544\" class=\"aligncenter size-full wp-image-4627\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-1.jpg 865w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-1-300x188.jpg 300w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/a><\/p>\n<p>Second, we need to create the <span style=\"color: #FF0000;\">primary key<\/span>.  This task is even easier.  Select the [MAKER_ID] column in the table designer and click the primary key tool bar button.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-NEW-INDEX-2\" width=\"822\" height=\"510\" class=\"aligncenter size-full wp-image-4629\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-2.jpg 822w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-2-300x186.jpg 300w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><\/a><\/p>\n<p>The primary key has been created.  However, our naming standard uses the column name instead of table name.  Find the PK_MAKES index and right click to access the sub-menu.  Select the re-name option.  Correct the name right in the object explorer window.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-3.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-NEW-INDEX-3\" width=\"417\" height=\"423\" class=\"aligncenter size-full wp-image-4632\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-3.jpg 417w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-3-295x300.jpg 295w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/a><\/p>\n<p>After you are done, you should have the following indexes created.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-4.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-NEW-INDEX-4\" width=\"417\" height=\"399\" class=\"aligncenter size-full wp-image-4631\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-4.jpg 417w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-NEW-INDEX-4-300x287.jpg 300w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/a><\/p>\n<p>Now, let&#8217;s explore some of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188388.aspx\">ALTER INDEX<\/a> graphical windows.<\/p>\n<p>There are some common weekly index tasks that you might encounter as a DBA.  I will be covering three of them.  These tasks can be found on the indexes node sub-menu.<\/p>\n<p>The first task is to <span style=\"color: #FF0000;\">disable<\/span> the index.  This is good idea if you have a large, manual data load. <\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DISABLE-INDEX-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DISABLE-INDEX-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DISABLE-INDEX-1\" width=\"705\" height=\"631\" class=\"aligncenter size-full wp-image-4634\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DISABLE-INDEX-1.jpg 705w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DISABLE-INDEX-1-300x268.jpg 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/a><\/p>\n<p>The second task is to <span style=\"color: #FF0000;\">rebuild<\/span> a disabled or highly fragmented index.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REBUILD-INDEX-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REBUILD-INDEX-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-REBUILD-INDEX-1\" width=\"704\" height=\"631\" class=\"aligncenter size-full wp-image-4636\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REBUILD-INDEX-1.jpg 704w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REBUILD-INDEX-1-300x268.jpg 300w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/a><\/p>\n<p>The third task is to <span style=\"color: #FF0000;\">reorganize<\/span> a slightly fragmented index.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REORGANIZE-INDEX-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REORGANIZE-INDEX-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-REORGANIZE-INDEX-1\" width=\"704\" height=\"632\" class=\"aligncenter size-full wp-image-4637\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REORGANIZE-INDEX-1.jpg 704w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-REORGANIZE-INDEX-1-300x269.jpg 300w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/a><\/p>\n<p>There are many properties that can be viewed or changed on an INDEX.  Right click the index name in the object explorer and select the properties option from the sub-menu.  <\/p>\n<p>The <span style=\"color: #FF0000;\">General<\/span> page shows a read only version of the information we can enter in the new index dialog box.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-11.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-11.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-INDEX-PROPERTIES-1\" width=\"858\" height=\"593\" class=\"aligncenter size-full wp-image-4641\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-11.jpg 858w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-11-300x207.jpg 300w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/a><\/p>\n<p>The <span style=\"color: #FF0000;\">Options<\/span> page has various choices that effect how a index works.  I have mainly worked with the storage section.  Fill factor, pad index, and sort in tempdb are some useful options.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-INDEX-PROPERTIES-2\" width=\"858\" height=\"597\" class=\"aligncenter size-full wp-image-4651\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-2.jpg 858w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-2-300x208.jpg 300w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/a><\/p>\n<p>The <span style=\"color: #FF0000;\">Storage<\/span> page shows a read only version of file groups and\/or partitioning that is being used.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-3.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-INDEX-PROPERTIES-3\" width=\"858\" height=\"594\" class=\"aligncenter size-full wp-image-4653\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-3.jpg 858w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-3-300x207.jpg 300w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/a><\/p>\n<p>The <span style=\"color: #FF0000;\">Fragmentation<\/span> page shows read only information about the characteristics of the index.  <\/p>\n<p>I am mainly interested in fragmentation percentage and the forwarded records.  Both will cause performance issues with you system.  Other properties are interesting when you are performing indexing tuning.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-4.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-INDEX-PROPERTIES-4\" width=\"858\" height=\"595\" class=\"aligncenter size-full wp-image-4655\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-4.jpg 858w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-4-300x208.jpg 300w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/a><\/p>\n<p>The <span style=\"color: #FF0000;\">Extended properties<\/span> page allows you to attach custom properties to the index.  I have used this option in the past to add a description (comment) to the index definition.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-5.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-5.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-INDEX-PROPERTIES-5\" width=\"859\" height=\"594\" class=\"aligncenter size-full wp-image-4656\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-5.jpg 859w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-INDEX-PROPERTIES-5-300x207.jpg 300w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/a><\/p>\n<p>Finally, let&#8217;s explore some of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms176118.aspx\">DROP INDEX<\/a> graphical windows.<\/p>\n<p>To drop an index, find the index name in the indexes node in the object explorer.  Right click the name and select the delete sub-menu option.  This will bring up the delete object menu below.  Click OKAY to remove the index or CANCEL to abort the operation.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DELETE-INDEX-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DELETE-INDEX-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DELETE-INDEX-1\" width=\"704\" height=\"632\" class=\"aligncenter size-full wp-image-4657\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DELETE-INDEX-1.jpg 704w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DELETE-INDEX-1-300x269.jpg 300w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/a><\/p>\n<p>In a nutshell, the indexing of tables is a major part of being a database administrator.  <\/p>\n<p>I have shown you a couple of the types of indexes that can be created on a table.  There are many more types such as <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190806.aspx\">covered<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc280372.aspx\">filtered<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb934196.aspx\">spatial<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/gg492153.aspx\">column store<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms187317.aspx\">fulltext<\/a> and\/or <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb934097.aspx\">XML<\/a> to be reviewed in the future.  <\/p>\n<p>In short, you should have a good understanding on how to CREATE, ALTER and DROP indexes using SSMS after reading this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the articles that I presented so far for database development have been centered around the exact Microsoft T-SQL syntax to perform a certain operation. At the University of Rhode Island, I learnt how to program in Pascal before typing in my first ANSI SQL statement. In short, I will always be some type of developer in my heart. However, many people do not come from a computer science and math background. The SQL Server Management Studio (SSMS) has menus and dialog boxes to achieve many of the same&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[769,732,768,31,770,310,774,773,12,743,15,776,746,75,771,772,28,741,470,754,775],"class_list":["post-4618","post","type-post","status-publish","format-standard","hentry","category-db-dev","tag-alter-index","tag-clustered-index","tag-create-index","tag-database-developer","tag-disable-index","tag-drop-index","tag-extended-properties","tag-fragmentation-page","tag-free-code","tag-general-page","tag-john-f-miner-iii","tag-non-clustered-index","tag-options-page","tag-primary-key","tag-rebuild-index","tag-reorganize-index","tag-sql-server","tag-sql-server-management-studio","tag-ssms","tag-storage-page","tag-unique-index"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/4618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4618"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/4618\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}