title: Can we use 'GO' multiple times in SQL Transaction?
body: <p>Can We use <code>GO</code> statement mutiple times in a <code>SQL Transaction</code>. I am having a long T-SQL script and I want to run it in a <code>SQL Transaction</code>. If all goes well then I will commit otherwise will rollback. </p>
  
  <p>But, While running that query I got error like <code>'create function must be the only statement in the batch'</code>. As I am creating and dropping many Functions and Procedures in that. </p>
  
  <p>I have not used <code>GO</code> anywhere in the script. My question is that - Can I use multiple times <code>GO</code> statement in that long script. Because, <code>GO</code> creates a batch and if batch executes successfully first time but fails next time then will <code>rollback transaction</code> statement be able to actually rollback that has been executed ?</p>
  
  <p>Structure of my script looks like :</p>
  
  <pre><code>PRINT 'Transaction Started'
  BEGIN TRY
      BEGIN TRAN
  
      Drop Function 
      ....
      ....
      Create Function
      ....
      ....
      Drop Procedure
      ....
      ....
      Lots of statements
      ....
      ....
  
      COMMIT TRAN
      PRINT 'Transaction Succeeded'
  END TRY
  BEGIN CATCH
      PRINT 'Transaction Failed'
      IF(@@TRANCOUNT &gt; 0)
          ROLLBACK TRAN
  END CATCH
  </code></pre>
  
  <p>I am creating this script to migrate some changes from newDB to oldDB in a single script.</p>