Редагувати

Поділитися через


Delete a Job Step Log

Applies to: SQL Server Azure SQL Managed Instance

Important

On Azure SQL Managed Instance, most, but not all SQL Server Agent features are currently supported. See Azure SQL Managed Instance T-SQL differences from SQL Server for details.

This topic describes how to delete a SQL Server Agent job step log.

Before You Begin

Limitations and Restrictions

When job steps are deleted their output log is automatically deleted.

Security

Permissions

Unless you are a member of the sysadmin fixed server role, you can only modify jobs that you own.

Using SQL Server Management Studio

To delete a SQL Server Agent job step log

  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.

  2. Expand SQL Server Agent, expand Jobs, right-click the job you want to modify, and then click Properties.

  3. In the Job Properties dialog box, delete the selected job step.

Using Transact-SQL

To delete a SQL Server Agent job step log

  1. In Object Explorer, connect to an instance of Database Engine.

  2. On the Standard bar, click New Query.

  3. Copy and paste the following example into the query window and click Execute.

    -- removes the job step log for step 2 in the job Weekly Sales Data Backup  
    USE msdb ;  
    GO  
    
    EXEC dbo.sp_delete_jobsteplog  
        @job_name = N'Weekly Sales Data Backup',  
        @step_id = 2;  
    GO  
    

For more information, see sp_delete_jobsteplog (Transact-SQL).

Using SQL Server Management Objects

Use the DeleteJobStepLogs methods of the Job class by using a programming language that you choose, such as Visual Basic, Visual C#, or PowerShell. For more information, see SQL Server Management Objects (SMO).

-- Uses PowerShell to delete all job step log files that have ID values larger than 5.  
$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$jb = $srv.JobServer.Jobs["Test Job"]  
$jb.DeleteJobStepLogs(5)