SQL Server timed jobs, scheduled execution of stored procedures

Source: Internet
Author: User

First of all, I want to say, I really is slag, a this thing to get a half-day, forget, directly into the subject bar.

The first step:

Write the stored procedure first.

You have two tables, you build it yourself.

<br data-filtered="filtered">ifexists(selectname fromsysobjects          wherename=‘StaySchoolNum‘and type=‘p‘)           drop proc  StaySchoolNum            go create proc StaySchoolNumasdeclare @init int,@totle intselect@init=count(*) fromdbo.dic_vehicle  whereparent_id=1   if@init=0   begin    insert intodic_vehicle values(1,1,‘0‘)   end      else         begin             select@totle=COUNT(*) fromdbo.tb_vehicle_Data v wherev.szInGateCode<>‘‘and v.szOutGateCode=‘‘                          update dic_vehicle set[email protected] whereparent_id=1          end          

  

Step two: Set up a timed job

1. Open the Local data connection and locate the SQL Server Agent in the left explorer (at the bottom)

2, "new" a job

3, in the "General" to fill in the name can be explained to see personal habits

4. Open "Step", click "New", Fill in "Name", select "Database", fill in the command blank with T-SQL statement, then point analysis.

5. Open "Schedule", click "New", set the schedule you want, then save.

6, click on "SQL Server Agent", right-start, that is, timed job start.

7. If you want the scheduled job to start automatically, find SQL Server agent (MSSQLSERVER) in the service, set to "automatic" mode

Step three: Generate scripts for scheduled jobs

Method 1, click the job under SQL Server agent, select the job you created--right-write the job script--create to, and then copy the scripting language

Method 2, found that bloggers wrote this (manage -sql Server Agent -Jobs (right mouse button )-All Tasks -Generate SQL script -Save to a SQL file under [Page]), I didn't find it.

Found this blogger write good, recommended: http://www.cnblogs.com/shuang121/archive/2011/11/10/2244482.html

SQL Server timed jobs, scheduled execution of stored procedures

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.