Share via


Delete a Job Step Log

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

  • Before you begin:  

    Limitations and Restrictions

    Security

  • To delete a SQL Server Agent job step log, using:

    SQL Server Management Studio

    Transact-SQL

    SQL Server Management Objects

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.

Arrow icon used with Back to Top link [Top]

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.

Arrow icon used with Back to Top link [Top]

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).

Arrow icon used with Back to Top link [Top]

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, seeSQL 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)

Arrow icon used with Back to Top link [Top]