mssql - batch

Batches

A batch is a group of one or more Transact-SQL statements sent at the same time from an application to SQL Server for execution. SQL Server compiles the statements of a batch into a single executable unit, called an execution plan. The statements in the execution plan are then executed one at a time.

Each Transact-SQL statement should be terminated with a semicolon.

A run-time error, such as an arithmetic overflow or a constraint violation, has one of the following effects:

Most run-time errors stop the current statement and the statements that follow it in the batch.

Some run-time errors, such as constraint violations, stop only the current statement. All the remaining statements in the batch are executed.

For example, assume there are 10 statements in a batch. If the fifth statement has a syntax error, no statements in the batch are executed.

If the batch is compiled and the second statement then fails while running, the results of the first statement are not affected because it has already executed.

@@! run-time errors, such as constraint violations, stop only the current statement.


Explicit Batches

An explicit batch is two or more SQL statements separated by semicolons (;).

Procedures

If a procedure contains more than one SQL statement

Arrays of Parameters

a parameterized SQL statement as an effective way to perform bulk operations.

INSERT INTO Lines (OrderID, Line, PartID, Quantity)
   VALUES (?, ?, ?, ?)