a Batch as a Unit of parsing
A batch is a set of commands that are parsed and executed as a unit. If the parsing is successful,
SQL Server will then attempt to execute the batch. In the event of a syntax error in the batch, the
whole batch is not submitted to SQL Server for execution. For example, the following code has three
batches, the second of which has a syntax error (FOM instead of FROM in the second query).
-- Valid batch
PRINT 'First batch';
USE TSQL2012;
GO
-- Invalid batch
PRINT 'Second batch';
SELECT custid FROM Sales.Customers;
SELECT orderid FOM Sales.Orders;
GO
-- Valid batch
PRINT 'Third batch';
SELECT empid FROM HR.Employees;
Because the second batch has a syntax error, the whole batch is not submitted to SQL Server for
execution. The first and third batches pass syntax validation and therefore are submitted for execution.
This code produces the following output, showing that the whole second batch was not executed.
First batch
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'Sales'.
Third batch
empid
-----------
2
7
1
5
6
8
3
9
4
(9 row(s) affected)
www.it-ebooks.info
Do'stlaringiz bilan baham: |