Combining create statements
Some object creation statements cannot be combined with other creation statement
and need to be the
first statement in a batch. Those are:
-
create default
-
create function
-
create procedure
-
create rule
-
create schema
-
create trigger
-
create view
Note that the
create table
statement is absent from this list!
The following works:
create procedure p2 as print 'p2';
execute p2;
go
The following does not work, it throws the error message MSG 111, Level 15, State 1… 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch:
drop procedure if exists p2;
create procedure p2 as print 'p2';
execute p2;
go
This does work again:
drop procedure if exists p2;
create procedure p2 as print 'p2';
execute p2;
go
This also works
drop procedure if exists p2;
create procedure p2 as print 'p2';
execute p2;
go