Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Server error – The SET SHOWPLAN statements must be the only statements in the batch

I am trying to generate a showplan table in SQL Server. I am getting this error when I try to do this

Msg 1067, Level 15, State 1, Line 0
The SET SHOWPLAN statements must be the only statements in the batch.

I tried on a simple query and the error still appear

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use Warehouse
SET SHOWPLAN_ALL ON;
GO

SELECT * FROM [Warehouse].[dbo].[Client]
GO

SET SHOWPLAN OFF;
GO

What exactly does the error mean by only statements in the batch? Removing the GO did not resolve the issue too (I thought GO created "batches"). Could this be due to SQL server rights?

>Solution :

In SSMS (and a few other client tools), GO is used as a batch separator (though it is commonly mistaken for a T-SQL keyword).

The error message means what it says: that particular SET statement has to be in its own batch (so not mixed with any other statements).

So:

Use Warehouse;
GO -- this ends the batch

SET SHOWPLAN_ALL ON;
GO -- this ends the batch

...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading