SQL Stored Procedure Optimization experience

Source: Internet
Author: User

After the field colleagues reflect, they use a good XML export tool has been error, often reported the database connection time-out, view the database has been found to have more than 100G space.

However, the data stored in the export process only 1000 data per time, near the manager said there is time to filter should not cause problems.

Pull the stored procedure to execute in SQL SERVER, it takes 5 minutes to find

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Border:none; "/>

--Create a temporary table to hold the data CREATE TABLE #temp (ID varchar (), name varchar (), zg_id varchar (), ks_id varchar (10))--insert data by time period Into #temp (id,name) Select Id,name from TB1 (nolock) where beginTime between ' 20150606 ' and ' 20150706 '--associating other tables by existing data, Complete other data update #tempset zg_id=b.idfrom #temp a,tb_zg B (nolock) where a.zg_id=b.idupdate #tempset ks_id=b.idfrom #temp a,tb_ KS B (nolock) where a.ks_id=b.id

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Border:none; "/>

Only thousands of of the data were queried.

After careful analysis, we have just started the stored procedure to insert three tables of data into a temporary table and then do the processing.

After the query found that three tables each table has more than 7 million rows of data, the associated fields of each table is the primary key, and the first table has been used for the time period to worry about, that is, only query the first table, and by the time period to worry about less than a second.

Because I inserted the data from the first table into a temporary table.


SQL Stored Procedure Optimization experience

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.