<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>

[{'answer_id': 12320, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 1, 'selected': False, 'text': '<p>For starters, always remember that <code>GO</code> is not a SQL keyword; it is merely a batch separator that is (generally) implemented/recognized by the client, not the server. So, depending on context and client, there really is no guarantee that the current database is preserved between batches.</p>\n'}, {'answer_id': 12384, 'author': 'Booji Boy', 'author_id': 1433, 'author_profile': 'https://Stackoverflow.com/users/1433', 'pm_score': 1, 'selected': False, 'text': "<p>If you are using a maintenance plan you'd probably be better off use the check database integrity task. If you really want to run you own maintenance written in t-sql then run it using a step in a job, not in a maintenance plan and the code above will work ok. Like Stu said the GO statement is client directive not a sql keyword and only seems to be respected by isql, wsql, osql, etc, clients and the sql agent. I think it works in DTS packages. Obviously, not in DTSX, though.   </p>\n"}, {'answer_id': 12623, 'author': 'Booji Boy', 'author_id': 1433, 'author_profile': 'https://Stackoverflow.com/users/1433', 'pm_score': 0, 'selected': False, 'text': "<p>You have a check datasbase integrity task and you double-clicked it choose MyDb and when the plan runs it only checks master?? weird. Are you sure you don't another plan running?  </p>\n"}]
['https://Stackoverflow.com/questions/12304', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1219/']