In Transact-SQL, a batch is a set of SQL statements submitted together and executed as a group, one after the other. Batches can be stored in command files.
Is an *.sql file containing several SQL statements considered a batch? What else do we consider a batch?
A batch is a completed group, collection, or quantity of something, especially something that's just been made. You might, for example, bake a batch of cookies to take to your new neighbor.
The definition of a batch means a group or collection of objects or the amount of something produced at one time. A example of a batch is two loaves of bread.
Definition of batch (Entry 1 of 3) 1 : the quantity baked at one time : baking. 2a : the quantity of material prepared or required for one operation specifically : a mixture of raw materials ready for fusion into glass.
Batch programming is a programming paradigm that can execute certain commands automatically at the level of an operating system such as DOS or Windows 7 / XP. A batch file is a stack of such commands. If it is retrieved with the command line, the system will execute each task listed in succession.
Is an *.sql file containing several sql statements considered a batch?
Sort of. A *.sql
file is often a batch, but it could also contain several batches. You delimit separate batches via a batch separator. You might need multiple batches in a file because some statements (especially certain ALTER
commands) can only be executed once per batch. This can make things like performing ALTER
s in a loop tricky, because certain statement (SET
) will apply through the end of a batch, and because Sql Server will having implicit transaction which commit at the end of each batch.
Another trick here is how you separate individual batches in a file/document. In 99% of Sql Server tools, the batch separator is "GO
". However, this is something that is configurable by the tool. It's not part of the SQL language itself, and therefore you can run into the odd person now and then who uses something else, or get confused that SQL Server complains if you send it a "GO" command directly.
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