Archive

Posts Tagged ‘SQL’

powershell crash course part 2

June 4, 2013 Leave a comment

Hi all ,

part 2 of PowerShell .. took a back stage and I just figured out that I do not need to reinvent the wheel .. because some of the dedicated powershell

sites do a lot better work at it … YES ,, its extremely useful for SQL admins too .. so I will direct you to that sites instead …PLAN just changed

SITES –> http://powershell.com/cs/

on this sites .. GO to TAB named EBOOKV2 .. which has 18 lesson online eBook

and it covers most of the basics we need to start with …

–> http://powershell.com/cs/blogs/ebookv2/default.aspx

below I will provide small descriptions of lessons and topics covered in the same ..

Chapter 1. The PowerShell Console

This chapter will introduce you to the PowerShell console and show you how to configure it, including font colors and sizes, editing and display options. Topics Covered: Starting PowerShell First Steps with the Console Incomplete

Chapter 2. Interactive PowerShell

PowerShell has two faces: interactivity and script automation. In this chapter, you will first learn how to work with PowerShell interactively. Then, we will take a look at PowerShell scripts. Topics Covered: PowerShell as a Calculator
It is time to combine commands whenever a single PowerShell command can’t solve your problem. One way of doing this is by using variables. PowerShell can store results of one command in a variable and then pass the variable to another command.
and so forth .. you get 18 lessons to get going with basics .. its extremely well explained and of help to ADmins ..
ENjoy 🙂

get running job name from sysprocesses

February 20, 2013 1 comment
English: Labeled (SQL) database icon with shor...

English: Labeled (SQL) database icon with shortcut identification (Photo credit: Wikipedia)

Spid-1

Spid-1 (Photo credit: Eexlebots)

sometimes we need to find out the job details if multiple jobs are running at once and are involved in blocking or any other server performance issues …

the master..sysprocesses have column named program_name that represents the program from where a particular SPID is originating ..

for running SQL jobs this will be a hexadecimal string .. we can use below method to get the actual name of the job from sysjobs table

1> get the substring of the running job from sysprocess .. have filtered out generic refresher ETC

select substring(program_name,55,7) ‘to search’
from master..sysprocesses
where program_name like ‘%agent%’ and program_name not like ‘%DatabaseMail – SQLAGENT -%’
and program_name not in (‘SQLAgent – Alert Engine’,’SQLAgent – Generic Refresher’,’SQLAgent – Email Logger’,’SQLAgent – Job invocation engine’,’SQLAgent – Job Manager’)

output will be similar to below

Output :

to search
2FE3386
A68D437
3253286

Get the job details from MSDB database by using the results you got from above query and replace them in where clause

1>

select *
from msdb..sysjobs
where job_id like ‘%A68D437%’

OR

2> if you have more than one job running replace below job_id %strings%

select *
from msdb..sysjobs
where job_id like ‘%A68D437%’ or job_id like ‘%4E742EB%’ or job_id like ‘%FAEDF18%’

Enjoy 🙂

Categories: General, T-sql Tags: , ,
Design a site like this with WordPress.com
Get started