1. Batch Processing
- Batching refers to a group of statements that contains one or more T-SQL statements that are sent from the application to the SQL Server server at once. The SQL Server server compiles the batch statement into an executable unit (that is, the execution plan), and the name of the execution plan executes once each time.
- The GO command indicates the end of the batch process. If there is no go command in the T-SQL script, it will be executed as a single batch.
- SQL Server says that the statements in the batch are compiled as a single execution plan, so the statements in the batch are submitted to the server together, so you can save on system overhead.
- Batch processing is required when something in the script has to happen before another thing or when it is separated.
- If the following statements appear in a single script and are combined with other statements, they need to be dispersed into their batches by using the GO statement.
Create default
CREATE PROCEDURE
Create Rule
Create Trigger
CREATE view
2. Scripts
- Scripts are the way batches exist, and one or more batch files are organized together as a script that saves the script to a disk file, which is the script file.
- Use statement
Used to set the current database. If it's just a generic script, it might actually be more beneficial to omit the use statement. In general, if you name a database-specific table in your script, you need the use command. If the script is used to modify a particular database, you can see that this is very helpful.
A brief introduction to batch and script in SQL Server