Error in SQL script: Only one statement is allowed per batch

I ran into this error when using SQL Server Data Tools and it was because I had a post-deployment script that was added to the project wrong.

In the project file, any database objects should have elements like

<Build Include="dbo\tables\mytable.sql"/>

But scripts should have

<None Include="myscript.sql"/>

However I added my script file, it ended up with a Build tag instead of a None. Changing it to None fixed the error.


I have found the problem. When I added the file in VS I forgot to set Build Action = None from the file properties. So changing that fixed the problem and the project now compiles.


Regardless this seems to be pretty old I stuck for some hours with that as well and I think this way could be helpful for many.

In Database project, files set as Build are considered as Database structure so just one statement is allowed in such file by design. Go nor any other batch terminator will change that behavior, that message is just mistake. More info here.

There is lot of other build options for files in such project. For your case it seems that PostDeploy. In such file you could have various commands like inserts etc.

Then you can use output of Database project as dacpac file for Data-Tier DB applications (Otherwise it's not included).