[SQL Server] allows your data to come and go freely-Batch Processing

Source: Internet
Author: User

For example, we need to create a database and create a table. If there are few fields in the table, we can manually add them to the table one by one.

What if there are many fields? I am afraid I cannot insert data one by one. Even if my hands are not tired, I cannot use it for a while, and my head will be dizzy ~

What should we do? Don't worry, batch processing is coming soon ~~~


What is batch processing?

Batch Processing: A group of statements that contain one or more T-SQL statements that are sent to the SQL Server server at a time from the application. The SQL Server server compiles the batch processing statement into an executable unit (that is, an execution plan). The language name in the execution plan is executed once each time.


How does batch processing exist?

Script: The batch processing method. Organizing one or more batch processing files together is a script. Saving the script to a disk file is a script file.


For example, you can write all the query statements in a text file and double-click a BAT file to automatically execute the statements in the text file.

First, add a new batch file, Linlin. bat

Next, add an SQL script file, Linlin. SQL

In Linlin. bat, enter:

osql  -U  sa  -P  123456 -i c:\linlin.sql 

Similarly, in the BAT file, enter the preceding line and enter the script in Linlin. SQL.

For example:

Use Database Name goselect * from table name go


The above small example is to execute SQL statements through batch processing. Let's take a look at it,Considerations for batch Creation:

1. Create default value createdefault, create rule
Only one statement can be submitted in the same batch for rule, create trigger, and create view.

2. The deleted object cannot be referenced again in the same batch.

3. Rules and default values cannot be immediately used in the same batch after they are bound to table fields or custom fields.

4. You cannot define a check constraint and use it in the same batch immediately.

5. A new field cannot be referenced immediately after a field name in the table cannot be modified.

6. Some set options set using the set statement cannot be applied to queries in the same batch.

7. If the first statement in the batch processing is the execute statement of a stored procedure, the execute keyword can be omitted.



I believe that we have learned batch processing, and we will be more comfortable in our work, so that data can come and go freely.



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.