How does SQL Server Schedule jobs (execute a stored procedure)

Source: Internet
Author: User

If you need to regularly execute a stored procedure or SQL statements of less than 3200 characters in SQL Server, you can use management> SQL Server proxy> job.

1. Choose "manage"> "SQL Server proxy"> "job" (right-click)> "create job">

2. Create a job property (general)-> name [customize the name of this job]-> the enabled box contains a check mark->

You can select or use the default [unclassified (local)]-> the owner is the default logon SQL Server user [or other logon options]->

Description [fill in the detailed description of this job];

[Procedure for creating a job category:

SQL Server proxy-> job-> right-click to select all tasks-> Add, modify, delete]

3. Create a job property (STEP)-> New-> step name [custom Step 1 name]-> type [Transact-SQL (tsql) script]->

Database [database to be operated]-> command

[If it is a simple SQL statement, write it directly. You can also open the button and enter a prepared *. SQL file.

To execute the stored procedure, enter

Exec p_procedure_name v_parameter1, [v_parameter2... V_parametern]

]

-> OK

(If there are multiple steps, you can call the new button below again; you can also insert, edit, or delete multiple existing steps );

4. Create job attributes (scheduling)-> Create scheduling-> name [custom scheduling name]-> enable the check box-> schedule-> repeatedly appear->

Change [scheduling schedule]-> OK

(If you only need to save this job, you can remove the check mark in the enabled box from the regular operation );

5. Create job attributes (notifications)-> use the default notification method [when a job fails, write it to a Windows ApplicationProgramSystem log]-> OK.

Some SQL Server knowledge related to job execution:

The SQLServerAgent service must run properly. The NT login user who starts it must be consistent with the NT login user who starts the SQL Server database.

Right-click a job to view the history of the job execution, or immediately start and stop the job.

Recently, when viewing the job history, we found that some jobs have many historical records and some have fewer historical records.

How can some jobs be retained for a period of time according to their own needs, for example, retaining the history of a month.

I read the online help document of SQL Server, which introduces:

Choose "manage"> "SQL Server proxy"> "right-click" properties ">" job system ">" limit the size of job history logs ">

The maximum job history log size (number of rows) is 1000 by default. If a machine has a large number of jobs, you must increase it, for example, 100000

The maximum number of lines in the history logs of each job is 100 by default. if the job is executed twice a day, you need to keep the logs for one month, which can be set to 60.

There is a mutual constraint between them. We can change it according to our own needs.

If the SQL Server server has changed its machine name, it may encounter

Error 14274: unable to add, update, or delete a job initiated on the MSX server (or its steps or scheduling)

Microsoft documents: http://support.microsoft.com/default.aspx? SCID = KB; en-US; 281642

The original server name is stored in the originating_server field of MSDB... sysjobs in SQL Server 2000.

The 24x7 system cannot change the name as described in the Microsoft document above.

So I thought, could MSDB... sysjobs update originating_server field to the new server name currently in use?

Use MSDB

Select * From sysjobs

Find the originating_server field or the job_id of the old server, and then execute the update statement:

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.