title: Python 3 failed to check whether the database exists and create it
body: <p>I'm a python beginner. I want to use Python 3 to check the <code>test2</code> database on the SQL server. If it doesn't exist, I will create it. However, I find that an error is reported and I don't know what to do?</p>
  <p>python code:</p>
  <pre><code>import pymssql 
   
   
  def conn():
      ret = pymssql.connect(host='DESKTOP-4CDQOMR', user = 'sa', password = '123456') 
      if ret:
          print(&quot;connect successfully!&quot;)
      else:
          print(&quot;connect failed!&quot;)
  
      return ret
          
  
   
   
  if __name__ == '__main__':
      conn = conn()  
      if conn:
          cursor = conn.cursor()
          sql = &quot;if not exist (select * from sys.databases where name = 'test2')&quot;
          conn.autocommit(True)
          cursor.execute(sql)
          conn.autocommit(False) 
          conn.close()
  </code></pre>
  <p>error information:</p>
  <pre><code>---------------------------------------------------------------------------
  MSSQLDatabaseException                    Traceback (most recent call last)
  src\pymssql.pyx in pymssql.Cursor.execute()
  
  src\_mssql.pyx in _mssql.MSSQLConnection.execute_query()
  
  src\_mssql.pyx in _mssql.MSSQLConnection.execute_query()
  
  src\_mssql.pyx in _mssql.MSSQLConnection.format_and_run_query()
  
  src\_mssql.pyx in _mssql.check_cancel_and_raise()
  
  src\_mssql.pyx in _mssql.maybe_raise_MSSQLDatabaseException()
  
  MSSQLDatabaseException: (156, b&quot;Incorrect syntax near the keyword 'select'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n&quot;)
  
  During handling of the above exception, another exception occurred:
  
  OperationalError                          Traceback (most recent call last)
  F:\jupyter\connect.py in &lt;module&gt;
       20         sql = &quot;if not exist (select * from sys.databases where name = 'test2')&quot;
       21         conn.autocommit(True)
  ---&gt; 22         cursor.execute(sql)
       23         conn.autocommit(False)
       24         conn.close()
  
  src\pymssql.pyx in pymssql.Cursor.execute()
  
  OperationalError: (156, b&quot;Incorrect syntax near the keyword 'select'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n&quot;)
  </code></pre>