title: Why do Sql Server 2005 maintenance plans use the wrong database for dbcc checkdb?
body: <p>This is a problem I have seen other people besides myself having, and I haven't found a good explanation.</p>
  
  <p>Let's say you have a maintenance plan with a task to check the database, something like this:</p>
  
  <pre><code>USE [MyDb]
  GO
  DBCC CHECKDB with no_infomsgs, all_errormsgs
  </code></pre>
  
  <p>If you go look in your logs after the task executes, you might see something like this:</p>
  
  <pre><code>08/15/2008 06:00:22,spid55,Unknown,DBCC CHECKDB (mssqlsystemresource) executed by NT AUTHORITY\SYSTEM found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.
  08/15/2008 06:00:21,spid55,Unknown,DBCC CHECKDB (master) executed by NT AUTHORITY\SYSTEM found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.
  </code></pre>
  
  <p>Instead of checking MyDb, it checked master and msssqlsystemresource.</p>
  
  <p>Why?</p>
  
  <p>My workaround is to create a Sql Server Agent Job with this:</p>
  
  <pre><code>dbcc checkdb ('MyDb') with no_infomsgs, all_errormsgs;
  </code></pre>
  
  <p>That always works fine.</p>
  
  <pre><code>08/15/2008 04:26:04,spid54,Unknown,DBCC CHECKDB (MyDb) WITH all_errormsgs&lt;c/&gt; no_infomsgs executed by NT AUTHORITY\SYSTEM found 0 errors and repaired 0 errors. Elapsed time: 0 hours 26 minutes 3 seconds.
  </code></pre>