title: How do I conditionally create a table in Sybase (TSQL)?
body: <p>OK, so Sybase (12.5.4) will let me do the following to DROP a table if it already exists:</p>
  
  <pre><code>IF EXISTS (
      SELECT 1
      FROM sysobjects
      WHERE name = 'a_table'
      AND type = 'U'
  )
  DROP TABLE a_table
  GO
  </code></pre>
  
  <p>But if I try to do the same with table creation, I always get warned that the table already exists, because it went ahead and tried to create my table and ignored the conditional statement. Just try running the following statement twice, you'll see what I mean:</p>
  
  <pre><code>IF NOT EXISTS (
      SELECT 1
      FROM sysobjects
      WHERE name = 'a_table'
      AND type = 'U'
  )
  CREATE TABLE a_table (
      col1 int not null,
      col2 int null
  )
  GO
  </code></pre>
  
  <p>Running the above produces the following error:</p>
  
  <blockquote>
    <p><em>SQL Server Error on (localhost)
    Error:2714 at Line:7 Message:There is
    already an object named 'a_table' in
    the database.</em></p>
  </blockquote>
  
  <p>What's the deal with that?!</p>