I am running a SQL script but getting an error:
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch
Here's my code:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'myproc') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[myproc] create PROCEDURE [dbo].[myproc] AS BEGIN select * from mytable END GO
How can I solve it?
Just add a GO on the line before the CREATE TRIGGER. 'CREATE TRIGGER' must be the first statement in a query batch.
Expand Stored Procedures, right-click the procedure to modify, and then select Modify. Modify the text of the stored procedure.
Run your statement in the following form:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'myproc') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[myproc] GO create PROCEDURE [dbo].[myproc] AS BEGIN select * from mytable END GO
Note the GO
batch separator after DROP PROCEDURE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With