Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. --This script can connect to multiple servers, and try to find where a stored procedure is used
  2. --I'll clean it up eventually and add a loop for this but for now I wanted to share what I had
  3. --NOTE: You must turn on the SQLCMD command in SSMS to get this to work.
  4. --This is done in Query > SQLCMDMode (Its just a toggle in the menu)
  5.  
  6. --Changes the connection in SSMS
  7. :CONNECT Server01 --CHANGE THIS
  8.  
  9. go
  10.  
  11. SELECT j.name
  12. FROM msdb.dbo.sysjobs AS j
  13. WHERE EXISTS
  14. (
  15. SELECT 1 FROM msdb.dbo.sysjobsteps AS s
  16. WHERE s.job_id = j.job_id
  17. AND s.command LIKE '%StoredProcedure%' --CHANGE THIS
  18. );
  19.  
  20. SELECT @@SERVERNAME --Lets us know we've got the right one
  21.  
  22. go
  23.  
  24. :CONNECT Server02 --CHANGE THIS
  25.  
  26. go
  27.  
  28. SELECT j.name
  29. FROM msdb.dbo.sysjobs AS j
  30. WHERE EXISTS
  31. (
  32. SELECT 1 FROM msdb.dbo.sysjobsteps AS s
  33. WHERE s.job_id = j.job_id
  34. AND s.command LIKE '%StoredProcedure%' --CHANGE THIS
  35. );
  36.  
  37. SELECT @@SERVERNAME
  38.  
  39. go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement