Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I have 4 SQL scripts that I want to run in a DACPAC in PostDeployment, but when I try to build the 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.

The scripts contain only INSERT statements in different tables on the DB. And all of them are structured like so

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

only on different tables and with different data.

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

PS: Adding 'GO' between statements as the error suggests doesn't do anything.

2 Answers

0 votes
by (40.7k points)

Even I have faced the same problem. I forgot to set Build Action = None from the file properties when I had added the file in VS. 

Therefore, setting the Build Action= None fixed the problem and now, the project compiles completely fine.

0 votes
ago by (1.5k points)
Possible solution are:
Try wrapping the statement independently in BEGIN…END blocks.
IF NOT EXISTS (SELECT 1 FROM dbo.Criteria WHERE Name = 'Mileage')
BEGIN
    INSERT INTO dbo.Criteria(Name) VALUES ('Mileage');
END

Check for Hidden Characters: Paste each script into a plain text editor to remove any invisible characters that could be causing parsing problems.
Divide into Different Batches: Divide each IF.INSERT block into separate scripts if possible, in order to identify poor logic.

Related questions

0 votes
0 answers
0 votes
1 answer
asked Jul 18, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...