TSQL to start a SQL job and check all running jobs


-- TSQL command to start a SQL job with deault settigns 
EXEC msdb..sp_start_job @job_name = 'JobName'

-- Check all running jobs 
exec msdb.dbo.sp_help_job @execution_status=1 

-- Stop a job
EXEC msdb..sp_stop_job @job_name = 'JobName'

-- Check Job history
SELECT @@SERVERNAME as MyServerName, name, run_date, run_time ,run_status 
FROM msdb.dbo.sysjobhistory jh
INNER JOIN msdb.dbo.sysjobs j ON jh.job_id = j.job_id
WHERE step_id = 0 AND name = 'UserLogBkup'
ORDER BY 3 DESC , 4 desc 

--
Advertisements
This entry was posted in commands, Productivity, SQL, SQL Query, Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s