title: Using "GO" in a SSDT post-deployment script
body: <p>My SQL Server 2008 R2 database gets deployed from a SSDT project I created.  One strange requirement in this case is to change one of the primary key columns to or from <code>IDENTITY</code> depending on where it's deployed. I'm not wild about the requirement but that's not my question.</p>
  
  <p>What I have done is set up a post-deployment script that should run conditionally, depending on where the deployment is occurring. So far, so good.</p>
  
  <p>In my script I am doing an <code>ALTER TABLE ADD</code> command to set up a new column, populate it and rename it to the old column. After this I try to do an <code>UPDATE</code> to the new column and it glitches because the column doesn't exist. I put a <code>GO</code> statement right under the <code>ALTER TABLE ADD</code> command and when I test-run the script in isolation, this solves the problem, everything works great.</p>
  
  <pre><code>-- Add a clone of the ID column with no Identity constraint
  ALTER TABLE Communication ADD CommunicationIdNoIdentity INT NOT NULL;
  GO
  UPDATE Communication
  SET CommunicationIdNoIdentity = CommunicationID;
  </code></pre>
  
  <p>However it appears this is not legal in the context of a post-deployment script. With the <code>GO</code> in place I get a build error right there: </p>
  
  <blockquote>
    <p>Error: SQL72007: The syntax check failed 'Unexpected end of file occurred.' in the batch near</p>
  </blockquote>
  
  <p>How can I get around this? The <code>BuildAction</code> on the file is set to "None" which I think is correct.</p>
  
  <p><strong>UPDATE:</strong> Although the error is emanating from the child script, I finally got it back to the parent.  If I do this:</p>
  
  <pre><code>IF @IsDeploymentToDatacenter = 'TRUE'
      :r .\FixIdColumnInCommunicationTable.SQL
  </code></pre>
  
  <p>it works.  If I do this (what I had originally), it fails with the errors I described, among others:</p>
  
  <pre><code>IF @IsDeploymentToDatacenter = 'TRUE'
  BEGIN
      :r .\FixIdColumnInCommunicationTable.SQL
  END
  </code></pre>