Change the email across all Job alerts using script in SQL Server

Thursday, October 4, 2012

As a DBA sometimes we get request for add/update/delete of DL’s – Distribution Lists (email groups) across all jobs on a SQL Server Instances. If the frequency of such request is very frequent then it’s better to write a script and run it on requests by simply modifying the email addresses.

Here is how we will do this:

We will take help of 2 tables  msdb.dbo.sysjobsteps and msdb.dbo.sysjobsteps

Query to retrive the list of jobs along with steps which satisfies the condition to search for an email (Simply update the “your-email-address-here” below and execute the query).

SELECT, js.step_name, js.command FROM msdb.dbo.sysjobsteps js WITH(NOLOCK)
LEFT JOIN msdb.dbo.sysjobs j WITH(NOLOCK)
ON j.job_id = js.job_id  
WHERE js.command  like '%<your-email-address-here>%'

Update the old DL with new:

UPDATE msdb.dbo.sysjobsteps
SET command = REPLACE(command,'<search-email-group>','<new-email-group>')
WHERE command  like '%<your-search-term-here>%'
Related Posts Plugin for WordPress, Blogger...


rose taylor said...

A legit online jobs scam commonly would guise as people who have pure intentions of helping others by sharing what products and schemes they have.
legit online jobs scam

Post a Comment

© Copyright 2010-2012 Learn MySQL All Rights Reserved.
Template powered by