title: How to check if a table already exists in the database?
body: <p>Now I am using something like: </p>
  
  <pre><code>IF (object_id('table', 'U') is not null)  
  AND (NOT EXISTS (SELECT * FROM [table] WHERE id = 0))  
      RETURN; 
  </code></pre>
  
  <p>to check if this 'table' already exists in my database but I get the next error message while running the script if there is no such table in the current database:</p>
  
  <blockquote>
    <p>Msg 208, Level 16, State 1, Line 5<br>
    Invalid object name 'table'.</p>
  </blockquote>
  
  <p>Is this correct way to check if a table exists in a database? Or may be I must change any settings of my SQL Management Studio?</p>
  
  <p><strong>ANSWER</strong>: I changed my script and everything works well:</p>
  
  <pre><code>IF (object_id('table', 'U') is not null)  
      IF (NOT EXISTS (SELECT * FROM [table] WHERE id = 0))  
          RETURN;  
  </code></pre>