?
Solved

Identify Agent jobs which target a specific DB

Posted on 2014-02-18
4
Medium Priority
?
315 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 69

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

764 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