title: VS2010 database project generates SQL03070 error with ALTER statements
body: <p>I've been struggling for a while with a newly set up Database Project for an SQL 2008 R2 database server in VS2010. I am not a database developer / administrator, but as things often are in IT it ended up on my desk.</p>
  
  <p>I created scripts for tables, views, stored procedures and functions using SSMS => Tasks => Generate Scripts functionality. No matter which options I choose for the script generation, I always end up with some problems, i.e. as soon as I use the <strong>IF NOT EXISTS</strong> option I get an SQL03070 error saying <em>"This statement is not recognized in this context."</em>. </p>
  
  <p>I also get the same error when I change <strong>CREATE [...]</strong> to <strong>ALTER [...]</strong>. Following a post on <a href="http://connect.microsoft.com/VisualStudio/feedback/details/665187/in-a-database-project-please-allow-alter-where-now-only-create-is-expected" rel="nofollow">Microsoft's Connect Website</a> this is to be expected as "The database project does not allow alters as it will dynamically determine if an ALTER or CREATE is necessary against a specifc database target." Fine with me, but when I choose <em>Execute SQL</em> from the context menu I do get an error if the specific object already exists in the database - I expected the dynamic generation of an ALTER statement in that case.</p>
  
  <p>Unfortunately, due to a lot of legacy code / objects in the database I cannot create or run a full deployment script, so basically the idea is to use VS2010 with TFS to have at least some of the advantages of source control when changing objects in the database. </p>
  
  <p>Always running into error SQL03070 though is not really an option, and importing the database using <em>Import Database Objects and Settings</em> from within VS2010 also does not work as intended as I don't have a single file for e.g. a table definition (with keys, indexes etc.) but multiple files that are hard to handle.</p>
  
  <p>The last option, setting the <em>Build Action</em> for the scripts to <em>Not in Build</em> results in the inability to run Code Analysis on those files, something we would also like to do.</p>
  
  <p>So basically my question is what would be the best approach for our set up to use database projects / TFS from within VS2010 without getting SQL03070 errors but with code analysis enabled? I do feel quite confused and apologize in case that some aspects of my problem might not be clear enough, please feel free to ask for more details and I will try to answer as good as I can.</p>
  
  <p>Thanks in advance</p>
  
  <p>G.</p>