SQL uses the stored procedure to import data in batches

Source: Internet
Author: User
Storedprocedure is a set of SQL statements for specific functions. It is a program written in the transact-SQL language provided by sqlserver. Compiled and stored in. A stored procedure is an important object in a database. You can specify the name of a stored procedure and provide parameters (if the stored procedure has parameters) to execute it. The stored procedure is written by flow control and SQL statements. After compilation and optimization, the stored procedure is stored on the database server. What is the stored procedure?

Stored procedure is a set of SQL statements for specific functions. It is a program written in the transact-SQL language provided by SQL server. Compiled and stored in. A stored procedure is an important object in a database. You can specify the name of a stored procedure and provide parameters (if the stored procedure has parameters) to execute it. A stored procedure is a process written by flow control and SQL statements. The procedure is compiled and optimized and stored on the database server. The stored procedure can be executed by an application through a single call, you can also declare variables. In addition, stored procedures can receive and output parameters, and return the status values for executing stored procedures.

Stored Procedure syntax

Create procedure [owner.] stored procedure name [; program id] [(parameter #1 ,... Parameter #1024)] [with {recompile | encryption | recompile, encryption}] [for replication]

Look at a simple instance

Create procedure order_tot_amt @ o_id int, @ p_tot int output as select @ p_tot = sum (unitprice * quantity) from orderdetails where ordered = @ o_id go

Next we will look at a batch import data instance using the stored procedure.


Declare @ mycounter int
Set @ mycounter = 0/* set variable */
While (@ mycounter <2)/* set the number of cycles */
Begin
Waitfor delay '000: 00: 10'/* delay Time: 10 seconds */
Insert into time_by_day
(Time_id, the_date, the_year, month_of_year, quarter, day_of_month)
Select top 1 time_id + 1 as time_id, the_date + 1 as the_date, year (the_date + 1)
As the_year, month (the_date + 1) as month_of_year, {fn quarter (the_date + 1)
} As quarter, day (the_date + 1) as day_of_month
From time_by_day
Order by time_id desc
Set @ mycounter = @ mycounter + 1
End

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.