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
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
...