title: Creating stored procedure in MS SQL through pyodbc
body: <p>I am trying to create a store procedure in master in mssql through python code. The following is my code:</p>
  
  <pre><code>import pyodbc
  
  conn = pyodbc.connect("driver={SQL Server};server=localhost; database=master; trusted_connection=true",
                        autocommit=True) 
  cursor = conn.cursor()
  sqlcommand = """
                  USE master
                  GO
                  CREATE PROCEDURE sp_myCustomSystemProc
                  AS
                  BEGIN
                      PRINT 'myCustomCode'
                  END
                  GO
                  EXEC sp_ms_marksystemobject 'sp_myCustomSystemProc'
               """     
  cursor.execute(sqlcommand)
  
  cursor.commit()
  
  conn.commit()
  </code></pre>
  
  <p>After running this python code, I am getting this error:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):  </p>
  
  <pre><code>File "auto_complete.py", line 27, in &lt;module&gt;
    cursor.execute(sqlcommand)  
  pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]
  Incorrect syntax near 'GO'. (102) (SQLExecDirectW); 
  [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]
  'CREATE/ALTER PROCEDURE' must be the first statement in a query batch. (111); 
  [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]
  Incorrect syntax near 'GO'. (102); 
  [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]
  Incorrect syntax near 'sp_myCustomSystemProc'. (102)")
  </code></pre>
  </blockquote>
  
  <p>Can anyone please help me to resolve this?</p>