A brief introduction to batch and script in SQL Server

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.