title: SQL Server - What are best practices for maintaining indexes?
body: <p>I'm reading up on indexes for optimizing database performance and would like to gather best practices for various database situations in terms of applying indexes.</p>
  
  <p>Take a totally non-indexed database with non-trivial amount of tables and rows, what rules do you use in determining what index is applied to what column of what type to achieve maximal performance? What query analyzing tricks to do use?</p>
  
  <p>As a start I got: (from <a href="http://asptutorials.net/SQL-Server/tutorial-on-indexes/" rel="nofollow noreferrer">http://asptutorials.net/SQL-Server/tutorial-on-indexes/</a>)</p>
  
  <ul>
  <li><p>For main or "header" tables such as a table of invoices, make a clustered index on the Primary Key of the table. </p></li>
  <li><p>For secondary or "details" tables such as "invoice_row", make a clustered index on the foreign key that groups the child records together (which in this example is "invoice_id"). This is because the majority of queries on the invoice_row table will be made in the invoice_id order rather than the invoice_row_id order. </p></li>
  <li><p>For all tables, make a non-clustered index on each of the foreign keys of the table. Don't concern yourself with covering indexes at this point. 
  Think about the selects queries that you will be performing on the table. What sort of "where" and "order by" statements will you be using? Make a non-clustered index on these columns. </p></li>
  <li><p>It is now time to start timing your typical queries and look for any slow ones. If you identify a particularly slow one, see if there is a way that you can add extra non-key columns to an index so that it becomes a covering index for that query. </p></li>
  </ul>
  
  <p>What other "rule-of-thumbs" can we collect? What tools to use?</p>