SQL Server: how to set a scheduled job

Source: Internet
Author: User
You can use -> SQL Server proxy -> Job.
1 , Management -> SQL Server proxy -> Job (right-click) -> Create a job ->

2 , New job attributes (General) -> Name [ Customize the job name ] -> The enabled box contains a check mark. ->

You can select or use the default [ Unclassified (local) ] -> The owner is the user logged on to SQL Server by default. [ Other Logon options are also available. ] ->

Description [ Enter the detailed description of this job ] ;

[ To create a job category:

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

3 , New job attributes (STEP) -> New -> Step name [ Custom Step 1 Name ] -> Type [ Transact-SQL (tsql) script ] ->

Database [ Database to operate ] -> Command

[ If it is a simple SQL statement, you can directly write it in. 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 ] -> The enabled box contains a check mark. -> Scheduling -> Repeated appearance ->

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 (notification) -> Use the default notification method. [ When the job fails, write the Windows Application System 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:

In management -> SQL Server proxy -> Right-click an attribute -> Operating 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)

I read Microsoft's document: 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:

Update Sysjobs Set Originating_server = ' New_server_name '
Where Job_id = ' B23BBEBE-A3C1-4874-A4AB-0E2B7CD01E14 '

(The number of affected rows is 1 Rows)

In this way, you can add, update, or delete errors 14274 .


If you want to migrate a job from one machine to another, you can keep the script for creating the job and run it on the other machine.

To export a script for all jobs, follow these steps:

Management -> SQL Server proxy -> Job (right-click) -> All tasks -> Generate an SQL script -> An SQL file saved to the Operating System

To export a script for a job, follow these steps:

Management -> SQL Server proxy -> Job -> Select the job to be transferred (right-click) -> All tasks -> Generate an SQL script -> An SQL file saved to the OS

Then, run the SQL script for creating the job saved just now on the target server.

(If the user who created the job or the user who reminded him does not exist, an error will occur;

We need to create a Windows user or SQL Server database logon on the target server,

You can also modify the script for creating a job to replace a user that does not exist on the target server with an existing user.

If the directory of the physical file that generates the log does not exist, make relevant modifications, such as converting D: \ To F: \.

String @ Command The command has a separator. Go An error occurs. you can remove it)
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.