Error in SQL script: only one statement allowed per batch

I have 4 sql scripts that I want to run in DACPAC in PostDeployment, but when I try to build a VS project for 3 of them, I get this error:

Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements. 

Scripts contain only INSERT expressions in different tables in the database. And they are all structured like this

 IF NOT EXISTS (SELECT 1 FROM dbo.Criteria WHERE Name = 'Mileage') INSERT INTO dbo.Criteria(Name) VALUES ('Mileage'); 

only for different tables and with different data.

My question is: why does VS complain about 3 of them when all the scripts are the same in terms of syntax and operations?

PS: adding "GO" between operators, as the proposed error does nothing.

+74
sql sql-server visual-studio-2012 dacpac
Sep 09 '13 at 12:42 on
source share
3 answers

I found a problem. When I added the file to VS, I forgot to set Build Action = None from the file properties. Thus, this change fixes the problem and the project is now compiled.

+173
Sep 09 '13 at 13:02
source share

Regardless of the fact that it seems pretty old, I got stuck for a few hours with this, and I think this method can be useful for many.

In the Database project files installed as Build are considered as a database structure, therefore only one statement is allowed in such a file by design. Go , nor any other party terminator will change this behavior, this message is simply a mistake. More details here.

There are many other file assembly options in this project. For your case, it seems that PostDeploy . In such a file, you can have various commands such as inserts , etc.

Then you can use the output of the database project as a dacpac file for DB-level data applications (otherwise it will not be included).

+1
Oct 28 '17 at 20:53 on
source share

Remove from (half-tables) from the last of each statement, and I'm not sure, but GO is not required between the above insertion instructions.

-one
Sep 09 '13 at 12:47 on
source share



All Articles