Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a batch?

Tags:

sql

tsql

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?

like image 857
carewithl Avatar asked Nov 09 '09 21:11

carewithl


People also ask

What is considered 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.

What is batch with example?

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.

What is the meaning of batch in English?

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.

What does batch mean in programming?

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.


1 Answers

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 ALTERs 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.

like image 176
Joel Coehoorn Avatar answered Sep 25 '22 23:09

Joel Coehoorn