Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Identify Agent jobs which target a specific DB

Posted on 2014-02-18
4
Medium Priority
?
318 Views
Last Modified: 2014-03-09
We have a SQL Server 2012 with multiple databases and several SQL Server Agent jobs.  Is there a way for me to quickly identify jobs which contain steps affecting a specific DB?
0
Comment
Question by:canuckconsulting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 1600 total points
ID: 39869185
1.  Check all the steps where the following is true:
SELECT  *
FROM    dbo.sysjobs j
        INNER JOIN sysjobsteps s ON j.job_id = s.job_id
WHERE   s.database_name = 'YourDatabaseName'

2. Check the contents of the command column for the database name as in:
SELECT  *
FROM    dbo.sysjobs j
        INNER JOIN sysjobsteps s ON j.job_id = s.job_id
WHERE   CHARINDEX('YourDatabaseName.', command) > 0
0
 
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 400 total points
ID: 39870736
Anthony's code looks good, except:

I wouldn't include the "." after the database name, because rather than multi-part object name -- db_name.schema.table_name -- the code might contain "use db_name select ... from schema.table_name".


Also, be aware that of course a proc called from a job may reference any number of other dbs within that proc, which the above code cannot identity.

For example, say you are looking for references to dbA.

An existing job might have code that runs:
EXEC dbB.dbo.proc1
and the proc could then reference objects in dbA.

There's really not a good way to programmatically trace all that down.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39872018
Anthony's code looks good, except:
I did think of that but I wanted to avoid any false positives.  But you make a good point.
0
 

Author Closing Comment

by:canuckconsulting
ID: 39916386
Thanks guys!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
What we learned in Webroot's webinar on multi-vector protection.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question