title: How to enable/disable trigger in procedure?
body: <p>I have two databases (<code>firstDB</code> and <code>secondDB</code>) on MS SQL server.
  There is procedure <code>[dbo].[MaintaineIndexes]</code> in <code>firstDB</code> and <code>DatabaseEventsTrigger</code> in <code>secondDB</code>.</p>
  <p>I want to disable <code>secondDB.DatabaseEventsTrigger</code> when I am running <code>[dbo].[MaintaineIndexes]</code>.</p>
  <p>So I tried:</p>
  <pre><code>ALTER PROCEDURE [dbo].[MaintaineIndexes] 
  AS
  BEGIN
  DISABLE TRIGGER DatabaseEventsTrigger ON secondDB; 
  ...
  ENABLE TRIGGER DatabaseEventsTrigger ON secondDB;
  END;
  </code></pre>
  <p>When I'm running procedure I'm getting error message: &quot;Cannot find the object &quot;secondDB&quot; because it does not exist or you do not have permissions.&quot;;</p>
  <p>Ok, then I tryed:</p>
  <pre><code>DISABLE TRIGGER DatabaseEventsTrigger ON ALL SERVER;
  </code></pre>
  <ul>
  <li>same error.</li>
  </ul>
  <p>Disabling trigger only working with this commands:</p>
  <pre><code>USE [secondDB]
  GO
  DISABLE TRIGGER DatabaseEventsTrigger ON DATABASE; 
  </code></pre>
  <p>But we can't use <code>USE</code> in procedures! So, how to enable/disable triggers in my situation?</p>