title: SQL Drop Index on different Database
body: <p>While trying to optimize SQL scripts, I was recommended to add indexes. </p>
  
  <p>What is the easiest way to specify what Database the index should be on?</p>
  
  <pre><code>IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableA')  
    DROP INDEX TableA.idx_TableA 
  
  IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableB')  
    DROP INDEX TableB.idx_TableB 
  </code></pre>
  
  <p>In the code above, TableA is in DB-A, and TableB is in DB-B. </p>
  
  <p>I get the following error when I change <code>DROP INDEX TableA.idx_TableA</code>  to <code>DROP INDEX DB-A.dbo.TableA.idx_TableA</code></p>
  
  <pre><code>Msg 166, Level 15, State 1, Line 2
  'DROP INDEX' does not allow specifying the database name as a prefix to the object name.
  </code></pre>
  
  <p>Any thoughts are appreciated.</p>