What is the difference between ;
and GO
in stored procedure in SQL Server ?
Actually, if I have a stored procedure in SQL server and wanna to p
I know this thread is old but I thought these other uses/differences might be handy for other searches like myself regarding GO
.
Anything after the GO
will not wind up in your sproc because the GO
will execute the CREATE/ALTER PROCEDURE
command. For example, if you run this...
CREATE PROCEDURE X AS SELECT 1 As X GO SELECT 2 As X
Then after running it you go back in to edit the procedure you will find that only the SELECT 1 As X
is in there because the GO
created the sproc and anything after it is assumed to be the next thing you are doing and not part of the sproc.
Think of GO
as a way of telling SSMS to send whatever is above it to the server for execution. The server never receives the GO
as that is just there to mark the end of a batch of command you want SSMS to send to the server.
If you have a scenario where you need to control execution flow in your stored procedure then you can use BEGIN TRANSACTION
and COMMIT TRANSACTION
for that and those are allowed in stored procedures.