title: Problems with SQL Server table indexing
body: <p><code>Subject</code> table:</p>
  
  <pre><code>Id int
  DepartmentId int
  GroupId int
  SchoolId int
  Name varchar(255)
  </code></pre>
  
  <p><strong>Queries</strong></p>
  
  <p>Query #1</p>
  
  <pre><code>SELECT * 
  FROM [Subject] t1, [Department] t2 
  WHERE t1.DepartmentId = t2.DepartmentId
  </code></pre>
  
  <p>Query #2</p>
  
  <pre><code>SELECT * 
  FROM [Subject] t1, [Group] t2, [Department] t3 
  WHERE t1.GroupId = t2.GroupId 
    AND t1.SchoolId = t3.DepartmentId
  </code></pre>
  
  <p>Query #3</p>
  
  <pre><code>SELECT * 
  FROM [Subject] t1, [Group] t2, [School] t3 
  WHERE t1.GroupId = t2.GroupId 
    AND t1.SchoolId = t3.SchoolId
  </code></pre>
  
  <p>Should I create a 3 indexes for table "subject", or just one is enough?</p>
  
  <p>Solution 1</p>
  
  <p>Create one index: <code>departmentId + GroupId + SchoolId</code></p>
  
  <p>Solution 2</p>
  
  <p>Create three indexes: </p>
  
  <ol>
  <li><code>DepartmentId</code> for stored proc 1.</li>
  <li><code>DepartmentId + GroupId</code> for stored proc 2.</li>
  <li><code>GroupId + SchoolId</code> for stored proc 3.</li>
  </ol>
  
  <p>Thank you so much!</p>