Is there a difference between "GO" and "BEGIN...END" in SQL Scripts/Stored Procedures? More specifically, does BEGIN...END specify batches just as GO does?
BEGIN and END are used in Transact-SQL to group a set of statements into a single compound statement, so that control statements such as IF … ELSE, which affect the performance of only a single SQL statement, can affect the performance of the whole group.
END at the start and end of a stored procedure and function. But it is not strictly necessary. However, the BEGIN... END is required for the IF ELSE statements, WHILE statements, etc., where you need to wrap multiple statements.
Begin SQL is a keyword used in the Method editor to indicate the beginning of a sequence of SQL commands that must be interpreted by the current data source of the process (the integrated SQL engine of 4D or any source specified via the SQL LOGIN command).
SET NOCOUNT ON prevents the sending of DONEINPROC messages to the client for each statement in a stored procedure.
GO is not actually a command understood by the server. It is simply a delimiter used by the client tool, e.g. Query Analyzer, to split the SQL up into batches. Each batch is then normally sent to the server separately. The client tool usually lets you configure the batch separator to be whatever you choose, GO is a convention.
BEGIN/END is a block marker which wraps a section of code in the same way that curly braces do in other languages.
One more little thing about GO.
Variables defined between GOs are only scoped to that region and do not exist outside that region.
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